Apparent math bug & question about FOR loops

Verbojuice
Hi,

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
There 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:


for <elemPtr; 1; elemTot> {


should be:


for <elemPtr; 1; %elemTot%> {

Verbojuice
Alex,

Thanks, I will get the hang of # and % at some point!

Freak
Maybe you're treating +/- as being right-associative instead of left-associative.

Alex
Quest 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

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums