Howcomes we can't have constant bools?
Howcomes we can't have constant bools?
...I haven't checked the compiler yet, but I'm assuming that you can't get your script to compile with something likein it?Code:const bool This_Is_True = true;
You could just use an integer (1 for true, 0 for false) and I think all your logical expressions will work fine. Something likeshould work.Code:const int Link_Is_Awesome = 1; if (Link_Is_Awesome && (Link->HP > 0)) { //...do whatever... }
Or just use a bool and try to not ever change it....?
What would you use a constant bool for? An optional game setting or something?
Well yes, I could use an integer, but it just looks a bit messy. And that if would give me a 'Cast from float to bool' warning every time I run it through the compiler, which isn't the end of the world, but it's quite annoying.
I've just gone with a bool that I'm not gonna change.
It's just for ease of reading really, I have some solidity checks which are generalised for left/right and for up/down, so they need to have a bool to tell the script which one to check.
Code:bool soliditycheck(int x, int y, bool horizvert){ if(horizvert){ //check for up down }else{ //check for left right } }
This is probably because the developers didn't think anyone would need a constant boolean declaration, since you can simply tack true or false into a conditional statement or argument list for a function. For example, ScaryBinary's
would becomeCode:const int Link_Is_Awesome = 1; if (Link_Is_Awesome && (Link->HP > 0)) { //...do whatever... }
I do agree, however, that such declarations should be allowed for ease of reading.Code:if (true && (Link->HP > 0)) { //...do whatever... }
And, yes, integers work, since a boolean is simply a special type of integer, and it isn't as messy as you think. You only need to change the declaration of your variables: the conditional statement does not need to be changed at all. So, in your example...
Does this make sense? I'm sorry if I'm confusing you.Code:bool soliditycheck(int x, int y, int horizvert){ if(horizvert){ //check for up down }else{ //check for left right } }
The 'if(horizvert)' line would cause the compiler to give me a 'Cast from float to bool' error every time I compiled it.Code:bool soliditycheck(int x, int y, int horizvert){ if(horizvert){ //check for up down }else{ //check for left right } }
I'd have to use 'if(horizvert==1)', and I don't really want to
I understand it, I was just wondering if there was any reason for it.
Wow. A boolean isn't considered a type of integer in ZScript? How odd.
Well, whatever you think is best. This thing is starting to sound like a bug to me, so I'd say post something in the Open Beta Bugs forum to let the ZC developers know about the compiler error.
There are no true integers in ZScript.
All integers are actually floats.
If you look in std.zh (the header file containing the pre-set constants), there's a line that says 'const int PI = 3.142;'
It's not really a bug, I'm assuming they missed this out on purpose, I was just wondering why.
You don't get a compile error for writing that, just a warning.
There are currently 1 users browsing this thread. (0 members and 1 guests)