Sign in to follow this  

Help! Variable initializing won't stick!

This topic is 4817 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

For some reason, I can't seem to assign an values to a variable. In the debugger, it shows 'no runtime value'. Here's what I'm doing:
...
gamestate *thisGame = new gamestate ;
initGame(thisGame) ;

...

void initGame(gamestate *thisGame){

	thisGame->rowcount = 0 ;
	thisGame->score = 0 ;
	thisGame->gameCount = 0 ;
}

It executes each line of code, but seems to just throw away the values. After each line in initGame(), the value in the debugger still shows 'no runtime value'. What's the problem?

Share this post


Link to post
Share on other sites
Hmm. If you're just hovering the mouse over the variables, it won't necessarily 'understand' it. To make sure if it's working, right click on the object (thisGame) and go to quickwatch - does it still say they're uninitialised?

Where in the program's flow are you checking the variable? The variable gameState will have a local scope of the function it's declared in - i.e. it won't be valid once that function returns.

Share this post


Link to post
Share on other sites
I tried the quick watch and for each element of the structure it shows <no runtime value>. I'm checking it immediately after it executes the line of code that sets the variable. It will execute thisGame->rowcount = 0 and still show <no runtime value>.

Share this post


Link to post
Share on other sites
This is even more strange. This produces the same result:


gamestate *thisGame = new gamestate ;
thisGame->rowcount = 0 // still shows <no runtime value>



Am I missing a step to using a pointer to this object?

Share this post


Link to post
Share on other sites
I can't believe this. When I did cout << thisGame->rowcount ; it wrote the correct value, but in the watch window it still showed the value as <no runtime value>. Not only that, but the original reason why I started this post seems to have corrected itself! The game wasn't keeping score correctly. Somewhere along the line I must have changed something because I know C++ is cool, but I don't think it's self-correcting. Thanks for your help everybody. ( I'll bet it fixed itself when I deleted the object file and I just didn't know it was fixed).

Share this post


Link to post
Share on other sites

This topic is 4817 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this