Jump to content
  • Advertisement
Sign in to follow this  
ELFanatic

odd problem

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

I'm having an odd problem. Probably just an oversight but I'm not seeing it. Here's the problem. void command(inputtedWords *); //Declaration in Adventure //Definition void Adventure::command(inputtedWords * sentence) { if(sentence->next->word == "go") { text = "Holy Cow"; textToType = true; } } Some reason the debugger is telling me that sentence is out of scope and it skips the if statement. I get no complaints from the compiler but the watch says it's out of scope as soon as it enters the function. I've changed sentence into other data types, same problem. I can't for the life of me figure out how it could be out of scope.

Share this post


Link to post
Share on other sites
Advertisement
I'm assuming C++ and char * strings.

you probably want the comparision to be
if (strcmp(sentence->next->word, "go")==0)

As it is, even if the strings are the same, == will return false, since the strings are held in different memory locations, and what you're really doing is comparing pointers to strings rather than the text in the two strings.

Not sure why it would think the variable is out of scope, but often that occurs to simple functions that are inlined... usually in a .h file, though with WPO it might occur to functions in .cpp files too.

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!