Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 206 207 [208] 209 210 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 908278 times)

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3105 on: October 17, 2012, 08:51:01 am »

I strongly recommend that you learn your syntax elsewhere.

(I'm mostly getting it from various tutorials online--and yeah, LCS is kind of weird :P)

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3106 on: October 17, 2012, 02:26:07 pm »

Welp, does Visual Studio 2010 not support enum class? D: The docs say it does, but it's not working. I get a bunch of rror C3381: '<unnamed-tag> and error C2059: syntax error : 'public' .

Code: [Select]
using namespace std;

public enum class ERROR {NONE = 0, TEST = -1};
public enum class ASCII {AT = 64};

The docs here say it supports enum class.

Why are you declaring it public, when it's in the global scope?

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3107 on: October 17, 2012, 05:09:25 pm »

No idea. I just saw the access part and wrote it.
I tried it without access keywords, too, so that't not the problem.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3108 on: October 17, 2012, 05:14:29 pm »

you should remove the class keyword from the enum declarations.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3109 on: October 17, 2012, 05:20:15 pm »

you should remove the class keyword from the enum declarations.

It's enum class, strongly defined enums, so that's not the point.
Googlefu tells me VC2010 doesn't support strongly typed enums.

Me sad.

did some python in school today.

tempted to drop my measly attempt in C++ for python, now.
Do it, you can learn languages later :3
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3110 on: October 17, 2012, 11:48:12 pm »

EEEEEeee I made a program!

Tell me of any bad habits I'm forming before I get used to them! (Other than not commenting shit)

Code: (main.cpp) [Select]
#include <iostream>
#include "Collatz_function.h"

using namespace std;

int main()
{
    int collatznumber;
    int collatzednumber;
    int numberofsteps;
    bool debug;
    short int debuginput;
    numberofsteps = 0;
    cout << "What number do you want to perform the Collatz conjecture on? ";
    cin >> collatznumber;
    cout << "Debug? (1/0) ";
    cin >> debuginput;
    if (debuginput==1) debug=true; // Have a feeling that this is kind of a dumb method to input a boolean.
    collatzednumber = collatznumber;
    while (collatzednumber > 1)
    {
        collatzcheck (collatzednumber);
        if (numberiseven) collatzednumber /= 2;
        else collatzednumber = (collatzednumber * 3) + 1;
        if (debug) cout << " ";
        if (debug) cout << collatzednumber;
        numberofsteps++;
    }
    return (numberofsteps);
}

Code: (Collatz_function.h) [Select]
#ifndef COLLATZ_FUNCTIONS
#define COLLATZ_FUNCTIONS

using namespace std;

bool numberiseven = true;

int collatzcheck (int a)
{
    if ((a%2)==0) numberiseven = true;
    else numberiseven = false;
}

#endif

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3111 on: October 17, 2012, 11:54:57 pm »

The numberisseven global bool is a very, very bad thing. Don't define global variables in headers, pretty much ever. Even program wide global variables need to be referenced with an extern.

Change that collatzcheck function to a bool function instead.

Code: [Select]
int collatzcheck (int a)
{
    if ((a%2)==0) numberiseven = true;
    else numberiseven = false;
}

becomes

Code: [Select]
bool collatzcheck (int a)
{
    if ((a%2)==0) return true;
    return false;
}

and
Code: [Select]
        collatzcheck (collatzednumber);
        if (numberiseven) collatzednumber /= 2;

becomes

Code: [Select]
        if (collatzcheck (collatzednumber)) collatzednumber /= 2;
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3112 on: October 17, 2012, 11:56:29 pm »

Will keep in mind.

(now THIS is how I learn things: jump right in, ask people to point out my mistakes :P)

EDIT: Heck, after re-reading, my code looks pretty stupid :P hehe, that's going to be with me for a while I'm sure.

EDIT 2: I'm sure there's a better way to use the debug stuff :P
« Last Edit: October 18, 2012, 12:03:42 am by Putnam »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3113 on: October 18, 2012, 12:20:37 am »

From the fluid & erosion sim I was working on spring quarter, I've been making it into a personal project. It now has better erosion and 3D visualization! :D
Video link of a timelapse of it working (mostly; the deposition code wasn't working as well as the image above, where I fixed it): http://www.youtube.com/watch?v=NUlf8gYSzL8

Algorithms for doing such were from this paper: http://www2.tech.purdue.edu/cgt/Facstaff/bbenes/private/papers/Stava08SCA.pdf
Though I still haven't fully implemented them...

The code generated initial terrain using diamond square, then has options to add water from a point source, dump it at random positions on the map ('rain'), etc. The image and video used the random 'rain' option. The erosion & water simulations are running in CUDA in realtime; something around 40FPS, even with the 2 million polygons being rendered. The rest of the program is in C++ and DirectX11.
« Last Edit: October 18, 2012, 12:25:40 am by alway »
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3114 on: October 18, 2012, 01:00:47 am »

EEEEEeee I made a program!

Tell me of any bad habits I'm forming before I get used to them! (Other than not commenting shit)

Code: (main.cpp) [Select]
#include <iostream>
#include "Collatz_function.h"

using namespace std;

int main()
{
    int collatznumber;
    int collatzednumber;
    int numberofsteps;
    bool debug;
    short int debuginput;
    numberofsteps = 0;
    cout << "What number do you want to perform the Collatz conjecture on? ";
    cin >> collatznumber;
    cout << "Debug? (1/0) ";
    cin >> debuginput;
    if (debuginput==1) debug=true; // Have a feeling that this is kind of a dumb method to input a boolean.
    collatzednumber = collatznumber;
    while (collatzednumber > 1)
    {
        collatzcheck (collatzednumber);
        if (numberiseven) collatzednumber /= 2;
        else collatzednumber = (collatzednumber * 3) + 1;
        if (debug) cout << " ";
        if (debug) cout << collatzednumber;
        numberofsteps++;
    }
    return (numberofsteps);
}

Code: (Collatz_function.h) [Select]
#ifndef COLLATZ_FUNCTIONS
#define COLLATZ_FUNCTIONS

using namespace std;

bool numberiseven = true;

int collatzcheck (int a)
{
    if ((a%2)==0) numberiseven = true;
    else numberiseven = false;
}

#endif

On top of what kai pointed out, I have a few more suggestions.

Code: [Select]
    cout << "Debug? (1/0) ";
    cin >> debuginput;
    if (debuginput==1) debug=true; // Have a feeling that this is kind of a dumb method to input a boolean.

I can't think of a better way to say this, so here goes: Your comment is correct. Slightly better:

Code: [Select]
    cout << "Debug? (1/0) ";
    cin >> debuginput;
    debug = debuginput; // Yay casting! The only downside to this is that any non-zero integer value will make debug true. Considering that the previous code allowed any non-zero integer to make debug false, that's still a slight improvement.

Slightly better-er:

Code: [Select]
    cout << "Debug? (true/false) ";
    cin >> boolalpha >> debug;

The boolalpha flag allows booleans to be read and written as "true" and "false" in streams, rather than 1 and 0. This method allows you to get rid of the debuginput variable, which means you saved at least 2 bytes of memory. Yay! In addition, "short int" is almost never used. Use "short" instead. The "int" is implied.

Why do you have both collatznumber and collatzednumber? collatznumber is read in from standard input, has its value assigned to collatzednumber, and then is never used again. You can combine those two variables into one.

You are returning numberofsteps from the main method. That's bad practice. The return value from the main method is used to indicate how the program exited. 0 means everything was successful, and non-zero values indicate various errors, defined by the program and/or operating system. Write numberofsteps to standard output, and return 0 instead.

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3115 on: October 18, 2012, 02:11:32 am »

I think everyone hit the important stuff, so m suggestion is to use more whitespace to increase readability: line breaks are your friend--try to break up your code into logical "paragraphs."
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3116 on: October 18, 2012, 02:24:20 am »

From the fluid & erosion sim I was working on spring quarter, I've been making it into a personal project. It now has better erosion and 3D visualization! :D
Video link of a timelapse of it working (mostly; the deposition code wasn't working as well as the image above, where I fixed it): http://www.youtube.com/watch?v=NUlf8gYSzL8

Algorithms for doing such were from this paper: http://www2.tech.purdue.edu/cgt/Facstaff/bbenes/private/papers/Stava08SCA.pdf
Though I still haven't fully implemented them...
That is Awesome.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3117 on: October 18, 2012, 02:54:28 am »

And of course I don't have an inkling of what's happening in that thesis ._.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3118 on: October 18, 2012, 03:22:59 am »

Excellent, I have GTK+ set up and a Hello World window running.


All of this include/linker directory stuff would have killed me a month ago, but it seems so easy now. There are only three project options you have to worry about, at least in Visual Studio:

- Additional Include Directories: If a library has an "include" folder, then include it. Inside these include folders are all of the header.h files. You would use them like "#include <header>".

- Additional Library Directories: If a library has a "lib" folder, then add it to this. Inside these are library.lib files. These are basically collections of compiled .cpp files, or at least that's how I think of it.

- Additional Dependencies: These are where the .lib files are added. This uses the Additional Library Directories, so you don't have to type in the full path for each .lib, you can just do "library.lib". Kind of annoying in VS, since you have to type in every single file name.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3119 on: October 18, 2012, 03:26:22 am »

I.
Hate.
Linker errors.

And why can't I just arbitrarily throw in a c library and statically link it?!
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))
Pages: 1 ... 206 207 [208] 209 210 ... 796