Jump to content
  • Advertisement
Sign in to follow this  
Robo-Link

this... is a retarded error [help]

This topic is 4105 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

void change() { bool b = true; if(black == 0 && b) { black = 1; b = false; } if(black == 1 && b) { black = 0; b = false; } } so... why doesnt that work? any lang that isnt super retard would easely get this right, but c++ says "OHHHHH black IS ALWAYS 0 LOL" i think this is really retard, and have been working on fixing it for 2 hours. everything i do at this is right, but c++ is doing something retarded that i cant see. i already know that the function is triggering, and that the bug is in this function, so would someone please help?

Share this post


Link to post
Share on other sites
Advertisement
0) Only a poor workman blames his tools. In the future, take a walk, a deep breath, and calm down before you come and post. You're letting your frustration control you, causing you to place the blame on the compiler (I assume this what you mean when you personify C++), which doesn't make you look good.

1) You haven't provided enough information. Post the actual error the compiler is giving you, in full, and the actual source code that you're using -- not a snippet you think is relevant, because (as you don't know what the problem is), you're in no position to judge what is an is not relevant.

The problem the code that you've presented is that "black" is an unknown identifier, which will cause a compiler error. Presumably your real code includes a definition and initialization of "black" somewhere, and you need to show that.

Share this post


Link to post
Share on other sites
what i want it to do
if(black == 0)
black = 1;

else if(black == 1)
black = 0;

if you run this it changes black from 0 to 1 or 1 to 0
no matter what i put it runs both though.

and i've even tried making it return int and return 0 after it changes it once.

also @Mod
wasnt it already in For Beginners? o.O;

Share this post


Link to post
Share on other sites
I think it's supposed to "flip" the value of black, of course there is an easier way.


void change()
{
if( black )
{
black = 0;
}
else
{
black = 1;
}
}


or even just replace the whole function with:

black = black ? 0 : 1;

Edit:

Quote:

if(black == 0)
black = 1;

else if(black == 1)
black = 0;


Why didn't you just do that? The OP made it seem like you didn't know the else statment, what the hell is the point of the variable "b" then?

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
0) Only a poor workman blames his tools. In the future, take a walk, a deep breath, and calm down before you come and post. You're letting your frustration control you, causing you to place the blame on the compiler (I assume this what you mean when you personify C++), which doesn't make you look good.

1) You haven't provided enough information. Post the actual error the compiler is giving you, in full, and the actual source code that you're using -- not a snippet you think is relevant, because (as you don't know what the problem is), you're in no position to judge what is an is not relevant.

The problem the code that you've presented is that "black" is an unknown identifier, which will cause a compiler error. Presumably your real code includes a definition and initialization of "black" somewhere, and you need to show that.


0)your right on this.

2) this is a closed source project, so i cant do that. and its not a compile error, its a logical one.

3) yea, black is an Int set to 0.

basicly you could just say the rest of the code is
int main()
{
int black = 0;
change();
cout << black;
change();
cout << black;
return 0;
}

Share this post


Link to post
Share on other sites
If, as it sounds, this is a boolean variable to gate whose turn it is, or which color the player is (in chess or othello, for example), and even more concise solution is

// Assuming
bool black = true;

// Then
void change()
{
black = !black;
}


But the OP still hasn't addressed the important questions. More context will be helpful. Closed source or not, you've already posted some of, so post more of it. We can't help you without more context -- you're clearly pretty new and or confused about this. The less information you give, the less we can help you. For example, your most recent post details an example that still won't compile (black is not visible in the scope of change) and if it did, wouldn't work the way you probably want (black is a local variable in main).

If you really want to be pointless secretive about your code, go write a mock program that exhibits the same unexpected behavior and post that.

And no, it was posted in Game Programming originally.

Share this post


Link to post
Share on other sites
Quote:
Original post by Scet
I think it's supposed to "flip" the value of black, of course there is an easier way.


void change()
{
if( black )
{
black = 0;
}
else
{
black = 1;
}
}


or even just replace the whole function with:

black = black ? 0 : 1;

Edit:

Quote:

if(black == 0)
black = 1;

else if(black == 1)
black = 0;


Why didn't you just do that? The OP made it seem like you didn't know the else statment, what the hell is the point of the variable "b" then?


cause

Quote:

if(black == 0)
black = 1;

else if(black == 1)
black = 0;


doesnt work >.<

nor does
black = black ? 0 : 1;

-.-|||

Share this post


Link to post
Share on other sites
Quote:
Original post by Robo-Link
doesnt work >.<


because?

Quote:
Original post by jpetrie
1) You haven't provided enough information. Post the actual error the compiler is giving you, in full

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!