Converting game from 1.4 to 2.0. Issue with code for <=.

F

Frederick Foote

Guest
Im trying to convert my game from 1.4 to 2. I'm getting the compile error seen below. Seems to revolve around the '<=' part. What is the gamemaker 2 change for this?

Errors:
Error : gml_GlobalScript_inventory_draw_optionbox(69) : Assignment operator expected
Error : gml_GlobalScript_inventory_draw_optionbox(69) : unexpected symbol "<=" in expression
Error : gml_GlobalScript_inventory_draw_optionbox(69) : malformed assignment
Error : gml_GlobalScript_inventory_draw_optionbox(69) : got '<=' expected ';'
Error : gml_GlobalScript_inventory_draw_optionbox(69) : unexpected symbol "<=" in expression
Error : gml_GlobalScript_inventory_draw_optionbox(69) : unexpected symbol "<=" in expression
Error : gml_GlobalScript_inventory_draw_optionbox(69) : malformed assignment
Error : gml_GlobalScript_inventory_draw_optionbox(69) : got '<=' expected ')'

Code:
for (a=1 a<=10 a+=1)
 

drandula

Member
Remember semicolons: "for(a=1; a<=10; a+=1)" to separate expressions inside statement.

Edit. That also read in your error message "got '<=' expected ';' ".

Edit2. Hopefully this helped, and it is good practice to use semicolons even though GameMaker can be forgiving sometimes :)
 
Last edited:
F

Frederick Foote

Guest
Thank You, I thought that was telling me to replace <= with ;. I thought it was just a mistake.
 

drandula

Member
You can read it that way if you don't know what it could mean šŸ˜…
But think computer reading your code when it tries build game of it. In for-statement it knows there will be three expressions, (because of keyword "for") but these expressions can be any length/type, so computer might not know when one ends and when second starts. Of course it can make assumptions (which GMS1 maybe did), but having semicolon indicating end of expression is sure-tell and avoids ambiguity.
Edit. Ambiguity is bad as then computer must make assumptions, which can be wrong and cause unwanted behaviour, but not cause error as they were interpreted as "correct".
 

FrostyCat

Redemption Seeker
I also suggest that you get in the habit of using var for iterating variables, which puts them in local scope. Not doing so avails you to all sorts of conflict between pieces of code.

The most common unwanted interaction is between looping variables inside and outside a script. Compare this correct implementation of capturing the values of 50 rolls of two dice:
GML:
for (var i = 0; i < 50; ++i) {
    rolls[i] = d6(2);
}
GML:
function d6(n) {
    var total = 0;
    for (var i = 0; i < n; ++i) {
        total += irandom_range(1, 6);
    }
    return total;
}
With this incorrect implementation that just crashes flat-out, for no reason other than failing to use local variables:
GML:
for (i = 0; i < 50; ++i) {
    rolls[i] = d6(2);
}
GML:
function d6(n) {
    total = 0;
    for (i = 0; i < n; ++i) {
        total += irandom_range(1, 6);
    }
    return total;
}
This should be a cautionary example for anyone who thinks they can get away with only using instance and global scope.
 
Top