• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

JASSHelper type comparison error without parenthesis

Status
Not open for further replies.
Level 39
Joined
Feb 27, 2007
Messages
5,014
I realize that there will probably never be an update to JASSHelper or vJASS in wc3 (blah blah Lua is the future old man... yes you're right) but I don't really understand why this produces an error:
JASS:
//ERROR "Cannot convert integer to boolean"
//      "Comparing the order/size of two variables only works on reals and integers"
if not Board.pcs[.x+dx][.y+dy]>0 then
    //...
endif


//NO ERROR because of the ()
if not (Board.pcs[.x+dx][.y+dy]>0) then
    //...
endif
.pcs is a static 2d struct array, so I'm just checking if a particular index of that array has been assigned to an allocated struct. What is produced by JASSHelper in the error case is the following:

if not s__s__Board_pcs[(s__Piece_x[this] + dx)*(20)+s__Piece_y[this] + dy] > 0 then which only compares integers to integers. Is this just a fake error that doesn't actually mean anything or what? Why does enclosing the line in parenthesis make it clear to JASSHelper that only integers are being compared with other integers?


Edit: Had I thought after I posted this... turns out it's the usage of "not" that is causing JASSHelper to freak out. Without the not, the line does not need () to compile properly. So instead this is just a discussion about this behavior. Should this make sense?
 
I think the unary  not operator may have a higher precedence over comparison operators for some inexplicable reason.

From the looks of it, the not operator treats Board.pcs[.x+dx][.y+dy] as a boolean value, which subsequently invalidates the comparison operator since it sees a boolean and a real value and may think that such behavior is undefined. (Redacted statement due to a mistake on my part)

Edit:
As noted by @Drake53, the JASS not operator does not implicitly convert integers or reals, which I have implied unintentionally. I've since redacted it.
 
Last edited:
Level 18
Joined
Jan 1, 2018
Messages
728

EDIT:
From the looks of it, the not operator treats Board.pcs[.x+dx][.y+dy] as a boolean value.
I tested this but this is not true, jass/vjass can not implicitly cast integer to boolean, for example 'if 0 then' or 'if not 1 then' will also cause errors.
Note that the OP has two errors, first "Cannot convert integer to boolean" because of the not operator, then "Comparing the order/size of two variables only works on reals and integers" because of the > operator.
 
Last edited:
Thanks for the clarification, @Drake53. I've updated my previous post to reflect the changes made.

Back on topic, I think the behavior of the not operator only makes sense in the context that the expression following the operator should be/hold an explicit boolean value. Implicit boolean values such as comparisons should be enclosed in parentheses so that they get evaluated first.
 
Status
Not open for further replies.
Top