KrimzonDestiny
Member
hello all, I feel like GM changed the way it handles arrays without me noticing. I seem to be having trouble with a 2D array. I'm trying to store the stats of 2 pawns within a 2D array, with 11 indexes:
TT and OO are both constants corresponding to 0 and 1. As you can probably guess, the stat abbreviations: HP, POW, DEF, etc... are also constants.
When the debug array message is printed at the end of scr_load, it reads and prints them no problem. However later, when I do the same thing in obj_trainee's step event, it only reads the values from index [0,0-10], and index [1,0-10] returns an index out of range error.
*********************************************************************
I figured out what was the wrong almost immediately. I wanted to delete this post but don't know how. I forgot to remove the creation of the stat array elsewhere in the project. So it got recreated, defaulting all values to 0. Sorry guys.
Code:
///obj_master_control_Create_1
globalvar stat; stat=array_create(11);
///obj_master_control_Step_1
scr_load();
Code:
///scr_load()
show_debug_message("LOAD_INI//LINE 1: Initiating load().");
//////////////////////////////////////////////////////////////
/// Initializing Varialbes
//////////////////////////////////////////////////////////////
//...battle stats
var pawn_cnt, stat_cnt;
pawn_cnt=2;//pc
stat_cnt=11;//sc
//...define as arrays
for(pc=0; pc<pawn_cnt; pc+=1){
for(sc=0; sc<stat_cnt; sc+=1){
//...saved and default stats
stat[pc,sc]=0;
stat_base[pc,sc]=0;
}
}
//...set default trainee stats
stat_base[TT,HP]=10;// health points
stat_base[TT,POW]=10;// power
stat_base[TT,DEF]=5;// defense
stat_base[TT,STM]=15;// stamina
stat_base[TT,AGL]=15;// agility
stat_base[TT,SPD]=19;// speed
stat_base[TT,CON]=10;// contitution
stat_base[TT,SPR]=10;// spirit
stat_base[TT,CRT]=10;// critical
stat_base[TT,MON]=100;// money
stat_base[TT,BLK]=5;// block
//...set default opponent stats
stat_base[OO,HP]=10;// health points
stat_base[OO,POW]=10;// power
stat_base[OO,DEF]=5;// defense
stat_base[OO,STM]=15;// stamina
stat_base[OO,AGL]=15;// agility
stat_base[OO,SPD]=19;// speed
stat_base[OO,CON]=10;// contitution
stat_base[OO,SPR]=10;// spirit
stat_base[OO,CRT]=10;// critical
stat_base[OO,MON]=100;// money
stat_base[OO,BLK]=5;// block
//////////////////////////////////////////////////////////////
///... Load Variables
//////////////////////////////////////////////////////////////
//...Open/Read save file
var file = "save_data.txt";
if(file_exists(file))
{
var f = file_text_open_read(file);
//...Read/Load Stats
for(pc=0; pc<pawn_cnt; pc+=1){
for(sc=0; sc<stat_cnt; sc+=1){
stat[pc,sc] = file_text_read_real(f ); file_text_readln(f);
}
}
file_text_close(f);
}
else
{
show_message("LOAD//LINE 58: file 'save_data.txt' not found. Loading defaults");
//...Load Pawn's Default Stats
for(pc=0; pc<pawn_cnt; pc+=1){
for(sc=0; sc<stat_cnt; sc+= 1){
stat[pc,sc] = stat_base[pc,sc];
}
}
}
//debug array message
show_message('scr_load, stat[TT,HP]='+string(stat[TT,HP]))//trainee HP stat
show_message('scr_load, stat[OO,HP]='+string(stat[OO,HP]))//opponent HP stat
/////////////////////////////////////////////////////////////////////
show_debug_message("LOAD_INI//LINE 42: Terminating load().");
data_loaded=1;
*********************************************************************
I figured out what was the wrong almost immediately. I wanted to delete this post but don't know how. I forgot to remove the creation of the stat array elsewhere in the project. So it got recreated, defaulting all values to 0. Sorry guys.
Last edited: