Legacy GM problem when loading game

A

Anton Provid

Guest
Hi, i got the problem when loading game:
Code:
instance_create argument 2 incorrect type (undefined) expecting a Number (YYGF)
 at gml_Script_scrLoad (line 17) -     var Inst = instance_create(SaveGrid[# a, 1],SaveGrid[# a, 2],SaveGrid[# a, 0]); //Create Instance at X/Y
############################################################################################
and here is the scrLoad():
Code:
///scrLoad();

ini_open('Save.ini'); //Open save ini
var InstNum = ini_read_real( 'Save', '0', 0); //Load number of instances

//Create grid
globalvar SaveGrid; //Create global variable for grid
SaveGrid = ds_grid_create(InstNum, 9); //Create grid as wide as building number

//Write saved grid to new grid
ds_grid_read(SaveGrid, ini_read_string('Save', '1', "")); //Populate grid with x/y/etc.

ini_close(); //Close ini

for(var a = 0; a <= InstNum; a ++){

    var Inst = instance_create(SaveGrid[# a, 1],SaveGrid[# a, 2],SaveGrid[# a, 0]); //Create Instance at X/Y
    Inst.Cost = SaveGrid[# a, 3];           //Building cost
    Inst.Occupants = SaveGrid[# a, 4];      //Number of occupants
    Inst.Name = SaveGrid[# a, 5];           //Little Human name variable
    Inst.HP = SaveGrid[# a, 6];             //Little human hp
    Inst.Money = SaveGrid[# a, 7];          //Little human money;
    Inst.image_index = SaveGrid[# a, 8];    //House sprite;
    
    Inst.Placed = 1; //Flag inst placed
    Inst.depth = -y; //Set depth of inst
    
    
}
Can someone help me with this?

Thank you in advance.
 
A

Anton Provid

Guest
with SaveGrid[# a,0] is represent for:
Code:
with(oParent_Placed){
    SaveGrid[# a, 0] = object_index; //Object to create
    SaveGrid[# a, 1] = x //Building x
    SaveGrid[# a, 2] = y //Building y
    SaveGrid[# a, 3] = Cost //Building cost
    SaveGrid[# a, 4] = Occupants; //Number of occupants
    SaveGrid[# a, 5] = Name; //Little Human name variable
    SaveGrid[# a, 6] = HP; //Little human hp
    SaveGrid[# a, 7] = Money; //Little human money;
    SaveGrid[# a, 8] = image_index; //House sprite;
    a++;
    
}
 

obscene

Member
SaveGrid[# a, 0] is returning -4. So check and see if it exists or has a value first before trying to create it.
 

Yal

🐧 *penguin noises*
GMC Elder
Error message says "undefined", which is different from noone, right? "Undefined" values from a ds_grid should mean you're reading from outside of the grid, so maybe you loop "a" too many values?
 
A

Anton Provid

Guest
Error message says "undefined", which is different from noone, right? "Undefined" values from a ds_grid should mean you're reading from outside of the grid, so maybe you loop "a" too many values?
Thank for your response, so can you help me explain or suggestion: how to solve this problem?
 

Yal

🐧 *penguin noises*
GMC Elder
Thank for your response, so can you help me explain or suggestion: how to solve this problem?
Check all loops accessing the grid and make sure you don't scroll outside the grid (e.g. using < instead of <= or vice versa changes the loop scope by 1). Or you could use is_undefined on the value you read, and if it is undefined, don't use it (you can use the continue keyword inside a loop to abort the current iteration and go to the next value right away).
 
A

Anton Provid

Guest
Check all loops accessing the grid and make sure you don't scroll outside the grid (e.g. using < instead of <= or vice versa changes the loop scope by 1). Or you could use is_undefined on the value you read, and if it is undefined, don't use it (you can use the continue keyword inside a loop to abort the current iteration and go to the next value right away).
wow, yes, i'm also using <= in loop so maybe it is the cause of problem. i will check it again. Btw, thank for your respond because this helps me so much.
 
Top