Independent and ambiguous variables
Apr 19, 2010 at 4:48am UTC
Ok so how do i make variables that are not part of any function but can be changed by other functions in the program....im trying to write a text game and i need this so i can have the inventory values per se i wanted the following:
1 2
bool knife = "false" ;
bool key = "false" ;
to run properly outside of a function
Apr 19, 2010 at 10:06pm UTC
Put them outside of all functions and on top of them. Then you can access them in any function from that code file.
Apr 20, 2010 at 6:59pm UTC
That seems the logical answer but this code
string currentroom = "outside" ;
when refernced with this code
1 2 3
if (currentroom == "oustide" )
{cout << "hi" ;}
else {cout << "error" ;}
always returns error....
and yes the string declaration is at the begining
Last edited on Apr 20, 2010 at 7:00pm UTC
Apr 20, 2010 at 7:12pm UTC
Unless it's a typo in your post and not in your code, you are comparing outside to oust ide, which will indeed output error.
Topic archived. No new replies allowed.