- Joined
- Aug 7, 2013
- Messages
- 1,338
Hi,
I am a bit confused by the behavior of struct arrays.
I have long believed that since they are integer arrays their default values are always 0, which also means that there's no struct in that position.
But this behavior I've observed suggests otherwise, which brings about a very strange contradiction, because I've been doing array struct[0] == 0 as a test if a position is empty (and it's never failed, until now that is).
I have a struct which has an array of structs inside it, and this part of the code loops over them only if their are actually structs inside them.
But, for whatever reason, the if statement actually fails. Even if subQuads never had a struct put there, it still runs the next calls. How do I know this?
My Quad structs require a JASS rect to be created--there's no other way to create one. So they have to be created like this: Quad q = Quad.create(someRect).
Now, when I did this check
it turns out on every faulty struct, the rect was also null. Meaning it was never ever created or initialized. Then how on earth could subQuads returns a value not equal to 0 if I never put a struct there?!
So now I have this for my loop, which seems to work.
But I've used checking if a struct is equal to 0 in all my other code, and it's never failed me once. So this is a very (annoying) contradiction.
I am a bit confused by the behavior of struct arrays.
I have long believed that since they are integer arrays their default values are always 0, which also means that there's no struct in that position.
But this behavior I've observed suggests otherwise, which brings about a very strange contradiction, because I've been doing array struct[0] == 0 as a test if a position is empty (and it's never failed, until now that is).
I have a struct which has an array of structs inside it, and this part of the code loops over them only if their are actually structs inside them.
JASS:
loop
exitwhen i == MAX_QUADS
if subQuads[i] != 0 then
call subQuads[i].flush()
call subQuads[i].destroy()
endif
set i = i + 1
endloop
But, for whatever reason, the if statement actually fails. Even if subQuads never had a struct put there, it still runs the next calls. How do I know this?
My Quad structs require a JASS rect to be created--there's no other way to create one. So they have to be created like this: Quad q = Quad.create(someRect).
Now, when I did this check
JASS:
if subQuads[i].rect == null then
call print("got a null rect when we shouldn't have"
endif
it turns out on every faulty struct, the rect was also null. Meaning it was never ever created or initialized. Then how on earth could subQuads returns a value not equal to 0 if I never put a struct there?!
So now I have this for my loop, which seems to work.
JASS:
loop
exitwhen i == MAX_QUADS
if subQuads[i].r != null then
call subQuads[i].flush()
call subQuads[i].destroy()
endif
set i = i + 1
endloop
But I've used checking if a struct is equal to 0 in all my other code, and it's never failed me once. So this is a very (annoying) contradiction.