- Edited
Hello. If i say something like
if (thing == 5){
};
And "thing" is not defined, i will get an error and my whole program will crash.
But say Its only not defined because it hasn't been defined yet. I can do a workaround like this:
if (thing){
if (thing == 5){
};
};
Then that code is only run if "thing" has been defined. Which is what I want.
But if im dealing with a boolean, such as
if (thing){
thing = true;
};
Its now no longer going to check if the variable exists, now its just going to check if its true. Therefore, if its already false, then the variable wont be converted to true! And if its not defined, it also wont get defined! This is NOT what i want. I already have the tools necessary to check to see if something is true or false, so why do these existence checks turn into boolean checks? Its useless and just injects bugs.
Is there any good way around this? 1s and 0s dont work because it reads it the same way, which is superbly annoying when i have number variables that are sometimes 0 or 1. [Mod: Spurious irrelevant link removed.] Am i forced to do something like use boolean-esque strings ('true' and 'false') in order to get the desired functionality? Can someone explain more into why it does this?