Apparent math bug & question about FOR loops
Verbojuice
26 Jul 2009, 15:45Hi,
Apparent math bug
Quest evaluates this wrongly: <elemTot; (%Map_X_Max% - %Map_X_Min% + 1) * (%Map_Y_Max% - %Map_Y_Min% + 1)>
Quest evaluates this correctly: <elemTot; (1 + %Map_X_Max% - %Map_X_Min%) * (1 + %Map_Y_Max% - %Map_Y_Min%)>
Using value 32 in the variables should give 1024 but the first version gives 900.
Question about for loops
The following appears not to execute, though no error is generated. Debug shows that elemTot has a value of 1024.
What I am dong wrong? Sample code attached.
Thanks, Verbojuice
Apparent math bug
Quest evaluates this wrongly: <elemTot; (%Map_X_Max% - %Map_X_Min% + 1) * (%Map_Y_Max% - %Map_Y_Min% + 1)>
Quest evaluates this correctly: <elemTot; (1 + %Map_X_Max% - %Map_X_Min%) * (1 + %Map_Y_Max% - %Map_Y_Min%)>
Using value 32 in the variables should give 1024 but the first version gives 900.
Question about for loops
The following appears not to execute, though no error is generated. Debug shows that elemTot has a value of 1024.
for <elemPtr; 1; elemTot> {
set string <Map_Locn[elemPtr]; TEST-VALUE>
msg <Element %elemPtr% is #Map_Locn[elemPtr]#>
}
What I am dong wrong? Sample code attached.
Thanks, Verbojuice
Alex
26 Jul 2009, 16:12There definitely seems to be something weird with the maths there - I'll fix this bug for Quest 4.1.1.
The "for" loop isn't running because this line:
should be:
The "for" loop isn't running because this line:
for <elemPtr; 1; elemTot> {
should be:
for <elemPtr; 1; %elemTot%> {
Verbojuice
26 Jul 2009, 16:29Alex,
Thanks, I will get the hang of # and % at some point!
Thanks, I will get the hang of # and % at some point!
Freak
26 Jul 2009, 19:07Maybe you're treating +/- as being right-associative instead of left-associative.
Alex
26 Jul 2009, 22:09Quest was always doing additions before subtractions. In v4.1.1 I've fixed this so that it does:
- multiplications and divisions first, left-to-right
- then, additions and subtractions, left-to-right
- multiplications and divisions first, left-to-right
- then, additions and subtractions, left-to-right