Fredrik
Member
What I've done is that I've used a variable to store a instance in a ini file, kinda.
I've preset a variable "var_room = 0;" in a save object's create event.
Then when a object representing a room is created I've made it so it (in it's create event) sets
var_room = obj_room_1; (also tried with var_room = id, and they both store the same id, so it doesn't matter
which one's used).
After this a script is set to store this variable in a ini file, which works just fine, so in the ini file I've got the rooms "id" and it's x and y value stored like this:
^ where the "ID" is the instance's id
When later loading the ini file again I've then made it so var_room = ini_read_real('Room 1','ID'0);
so then the variable "var_room" will be the instance's id as saved in the ini file, and after that I got
instance_create(x,y,var_room); Where I'd then guess that since "var_room" holds the saved instance's id it would create that object, but it doesn't, it fails to find the instance id and at this point I have no idea why.
Can also mention that the above code does not represent the entire code and is rather a shorter example.
-------------------------
Entire code below
-------------------------
obj_save: create event
obj_save: step event
obj_generate_default: alarm 0
(the object executing the load script and creating the instances).
scr_save
scr_load
Saved ini file
Really hoping that someone can spot a simple mistake, something like that I cant use instance create with a variable representing a instance's id or something like that.
I've preset a variable "var_room = 0;" in a save object's create event.
Then when a object representing a room is created I've made it so it (in it's create event) sets
var_room = obj_room_1; (also tried with var_room = id, and they both store the same id, so it doesn't matter
which one's used).
After this a script is set to store this variable in a ini file, which works just fine, so in the ini file I've got the rooms "id" and it's x and y value stored like this:
Code:
[Room 1]
Y="-736.000000"
X="-96.000000"
ID="252.000000"
When later loading the ini file again I've then made it so var_room = ini_read_real('Room 1','ID'0);
so then the variable "var_room" will be the instance's id as saved in the ini file, and after that I got
instance_create(x,y,var_room); Where I'd then guess that since "var_room" holds the saved instance's id it would create that object, but it doesn't, it fails to find the instance id and at this point I have no idea why.
Can also mention that the above code does not represent the entire code and is rather a shorter example.
-------------------------
Entire code below
-------------------------
obj_save: create event
Code:
/// Preset room numbers.
// preset all room number variables.
rmstart = 0; rmdspstart = 0;
rm1 = 0; rmdps1 = 0;
rm2 = 0; rmdps2 = 0;
rm3 = 0; rmdps3 = 0;
rm4 = 0; rmdps4 = 0;
rm5 = 0; rmdps5 = 0;
rm6 = 0; rmdps6 = 0;
rm7 = 0; rmdps7 = 0;
rm8 = 0; rmdps8 = 0;
rm9 = 0; rmdps9 = 0;
rm10 = 0; rmdps10 = 0;
Code:
/// Reset room numbers.
// reset all room numbers when generating a new level.
if global.remove = 1
{
rmstart = 0; rmdspstart = 0;
rm1 = 0; rmdps1 = 0;
rm2 = 0; rmdps2 = 0;
rm3 = 0; rmdps3 = 0;
rm4 = 0; rmdps4 = 0;
rm5 = 0; rmdps5 = 0;
rm6 = 0; rmdps6 = 0;
rm7 = 0; rmdps7 = 0;
rm8 = 0; rmdps8 = 0;
rm9 = 0; rmdps9 = 0;
rm10 = 0; rmdps10 = 0;
}
(the object executing the load script and creating the instances).
Code:
if !file_exists('save.ini') // generate new level if a save file doesn't exists.
{
randomize();
if global.currentfloor < 4
{
choose_room = choose (1,2,3,4,5,6,7,8,9);
if choose_room = 1 {instance_change(obj_room_14,1)}
if choose_room = 2 {instance_change(obj_room_1,1)}
if choose_room = 3 {instance_change(obj_room_2,1)}
if choose_room = 4 {instance_change(obj_room_3,1)}
if choose_room = 5 {instance_change(obj_room_4,1)}
if choose_room = 6 {instance_change(obj_room_5,1)}
if choose_room = 7 {instance_change(obj_room_6,1)}
if choose_room = 8 {instance_change(obj_room_7,1)}
if choose_room = 9 {instance_change(obj_room_13,1)}
}
if global.currentfloor > 3
{
choose_room = choose (1,2,3,4,5,6,7,8,9,10,11);
if choose_room = 1 {instance_change(obj_room_10,1)}
if choose_room = 2 {instance_change(obj_room_1,1)}
if choose_room = 3 {instance_change(obj_room_2,1)}
if choose_room = 4 {instance_change(obj_room_3,1)}
if choose_room = 5 {instance_change(obj_room_4,1)}
if choose_room = 6 {instance_change(obj_room_7,1)}
if choose_room = 7 {instance_change(obj_room_8,1)}
if choose_room = 8 {instance_change(obj_room_9,1)}
if choose_room = 9 {instance_change(obj_room_11,1)}
if choose_room = 10 {instance_change(obj_room_12,1)}
if choose_room = 11 {instance_change(obj_room_14,1)}
}
} else // Load in saved level if savefile exists.
{
script_execute(scr_load);
{
var obj = obj_save;
instance_create(obj.rmstart.x,obj.rmstart.y,obj.rmstart); // room 0.
instance_create(obj.rm1.x ,obj.rm1.y ,obj.rm1); // room 1.
instance_create(obj.rm2.x ,obj.rm2.y ,obj.rm2); // room 2.
instance_create(obj.rm3.x ,obj.rm3.y ,obj.rm3); // room 3.
instance_create(obj.rm4.x ,obj.rm4.y ,obj.rm4); // room 4.
instance_create(obj.rm5.x ,obj.rm5.y ,obj.rm5); // room 5.
instance_create(obj.rm6.x ,obj.rm6.y ,obj.rm6); // room 6.
instance_create(obj.rm7.x ,obj.rm7.y ,obj.rm7); // room 7.
instance_create(obj.rm8.x ,obj.rm8.y ,obj.rm8); // room 8.
instance_create(obj.rm9.x ,obj.rm9.y ,obj.rm9); // room 9.
instance_create(obj.rm10.x,obj.rm10.y,obj.rm10); // room 10.
}
}
Code:
// Save the game / create a savefile.
ini_open('save.ini');
// Variables.
ini_write_real('Variables','Floor',global.currentfloor); // save current floor / level.
// Player variables.
ini_write_real('Player variables','X',player.x); // save player.x.
ini_write_real('Player variables','Y',player.y); // save player.y.
ini_write_real('Player variables','Z',player.z); // save player.z.
// Save room number / level generation.
// room 0.
ini_write_real('Room 0','ID',obj_save.rmstart);
ini_write_real('Room 0','X' ,obj_save.rmstart.x);
ini_write_real('Room 0','Y' ,obj_save.rmstart.y);
// room 1.
ini_write_real('Room 1','ID',obj_save.rm1);
ini_write_real('Room 1','X' ,obj_save.rm1.x);
ini_write_real('Room 1','Y' ,obj_save.rm1.y);
// room 2.
ini_write_real('Room 2','ID',obj_save.rm2);
ini_write_real('Room 2','X' ,obj_save.rm2.x);
ini_write_real('Room 2','Y' ,obj_save.rm2.y);
// room 3.
ini_write_real('Room 3','ID',obj_save.rm3);
ini_write_real('Room 3','X' ,obj_save.rm3.x);
ini_write_real('Room 3','Y' ,obj_save.rm3.y);
// room 4.
ini_write_real('Room 4','ID',obj_save.rm4);
ini_write_real('Room 4','X' ,obj_save.rm4.x);
ini_write_real('Room 4','Y' ,obj_save.rm4.y);
// room 5.
ini_write_real('Room 5','ID',obj_save.rm5);
ini_write_real('Room 5','X' ,obj_save.rm5.x);
ini_write_real('Room 5','Y' ,obj_save.rm5.y);
// room 6.
ini_write_real('Room 6','ID',obj_save.rm6);
ini_write_real('Room 6','X' ,obj_save.rm6.x);
ini_write_real('Room 6','Y' ,obj_save.rm6.y);
// room 7.
ini_write_real('Room 7','ID',obj_save.rm7);
ini_write_real('Room 7','X' ,obj_save.rm7.x);
ini_write_real('Room 7','Y' ,obj_save.rm7.y);
// room 8.
ini_write_real('Room 8','ID',obj_save.rm8);
ini_write_real('Room 8','X' ,obj_save.rm8.x);
ini_write_real('Room 8','Y' ,obj_save.rm8.y);
// room 9.
ini_write_real('Room 9','ID',obj_save.rm9);
ini_write_real('Room 9','X' ,obj_save.rm9.x);
ini_write_real('Room 9','Y' ,obj_save.rm9.y);
// room 10.
ini_write_real('Room 10','ID',obj_save.rm10);
ini_write_real('Room 10','X' ,obj_save.rm10.x);
ini_write_real('Room 10','Y' ,obj_save.rm10.y);
ini_close();
Code:
// Load created savefile.
ini_open('save.ini');
// Variables.
global.currentfloor = ini_read_real('Variables','Floor',1); // Load current floor / level.
// Player variables.
if global.currentfloor = 1
{
player.x = 336;
player.y = -137;
player.z = 36;
} else
{
player.x = 336;
player.y = -495;
player.z = 32;
}
// Load room number / level generation.
// room 0.
obj_save.rmstart = ini_read_real('Room 0','ID',0);
obj_save.rmstart.x = ini_read_real('Room 0','X' ,0);
obj_save.rmstart.y = ini_read_real('Room 0','Y' ,0);
// room 1.
obj_save.rm1 = ini_read_real('Room 1','ID',0);
obj_save.rm1.x = ini_read_real('Room 1','X' ,0);
obj_save.rm1.y = ini_read_real('Room 1','Y' ,0);
// room 2.
obj_save.rm2 = ini_read_real('Room 2','ID',0);
obj_save.rm2.x = ini_read_real('Room 2','X' ,0);
obj_save.rm2.y = ini_read_real('Room 2','Y' ,0);
// room 3.
obj_save.rm3 = ini_read_real('Room 3','ID',0);
obj_save.rm3.x = ini_read_real('Room 3','X' ,0);
obj_save.rm3.y = ini_read_real('Room 3','Y' ,0);
// room 4.
obj_save.rm4 = ini_read_real('Room 4','ID',0);
obj_save.rm4.x = ini_read_real('Room 4','X' ,0);
obj_save.rm4.y = ini_read_real('Room 4','Y' ,0);
// room 5.
obj_save.rm5 = ini_read_real('Room 5','ID',0);
obj_save.rm5.x = ini_read_real('Room 5','X' ,0);
obj_save.rm5.y = ini_read_real('Room 5','Y' ,0);
// room 6.
obj_save.rm6 = ini_read_real('Room 6','ID',0);
obj_save.rm6.x = ini_read_real('Room 6','X' ,0);
obj_save.rm6.y = ini_read_real('Room 6','Y' ,0);
// room 7.
obj_save.rm7 = ini_read_real('Room 7','ID',0);
obj_save.rm7.x = ini_read_real('Room 7','X' ,0);
obj_save.rm7.y = ini_read_real('Room 7','Y' ,0);
// room 8.
obj_save.rm8 = ini_read_real('Room 8','ID',0);
obj_save.rm8.x = ini_read_real('Room 8','X' ,0);
obj_save.rm8.y = ini_read_real('Room 8','Y' ,0);
// room 9.
obj_save.rm9 = ini_read_real('Room 9','ID',0);
obj_save.rm9.x = ini_read_real('Room 9','X' ,0);
obj_save.rm9.y = ini_read_real('Room 9','Y' ,0);
// room 10.
obj_save.rm10 = ini_read_real('Room 10','ID',0);
obj_save.rm10.x = ini_read_real('Room 10','X' ,0);
obj_save.rm10.y = ini_read_real('Room 10','Y' ,0);
ini_close();
Code:
[Room 10]
Y="-2176.000000"
X="192.000000"
ID="249.000000"
[Room 9]
Y="-1312.000000"
X="192.000000"
ID="248.000000"
[Room 8]
Y="-1600.000000"
X="192.000000"
ID="247.000000"
[Room 7]
Y="-736.000000"
X="-384.000000"
ID="246.000000"
[Room 6]
Y="-736.000000"
X="-384.000000"
ID="246.000000"
[Room 5]
Y="-1024.000000"
X="-96.000000"
ID="245.000000"
[Room 4]
Y="-1888.000000"
X="192.000000"
ID="240.000000"
[Room 3]
Y="-1024.000000"
X="-384.000000"
ID="237.000000"
[Room 2]
Y="-1024.000000"
X="-384.000000"
ID="237.000000"
[Room 1]
Y="-1024.000000"
X="192.000000"
ID="253.000000"
[Room 0]
Y="-736.000000"
X="192.000000"
ID="257.000000"
[Player variables]
Z="2.000000"
Y="-495.000000"
X="336.000000"
[Variables]
Floor="4.000000"