GMS 2 [solved]removal from instance_create script if the object was destroyed

sinigrimi

Member
Hello! When I enter the room, it reproduces the blocks, but when I move to the next and return to the first, nothing is reproduced in it :(
p.s .: rooms are not from GM but are generated in the same GM Room after moving outside the camera.


I would also like to know if I can mark these objects somehow so that when I destroy the object, he crosses himself out of ds_list?
Code:
var num = RoomGen_GetRoomNumber(global.RoomGen_x, global.RoomGen_y);

var map = RoomGen_GetRoomMap(num);
if (ds_list_empty(map[?"room_type_save_changes"])){
    #region  case #0
    //case 0: //#1 bee
        ds_list_add(map[?"room_type_save_changes"],(instance_create_layer(180,300,"Instances",oStone)));
        ds_list_add(map[?"room_type_save_changes"],(instance_create_layer(300,300,"Instances",oStone)));
        ds_list_add(map[?"room_type_save_changes"],(instance_create_layer(420,300,"Instances",oStone)));

}
#endregion
 
if (!ds_list_empty(map[?"room_type_save_changes"]))
for (var a = 0; a<map[?"room_type_save_changes"]; a++;){
ds_list_find_value(map[?"room_type_save_changes"],a)
}
please help
really have to enter a bunch of data for each spawn? tell me, can I immediately play the spawn string from ds_list or other ds system


upd: ds_list does not produce the value "instance_create" is there any other way? I need that upon destruction the object crosses itself out of the list and is no longer recreated when the script is executed ... this is a terrible undertaking but it is necessary
 
Last edited:

samspade

Member
I cleaned up the code a little below. I'm actually surprised it compiled with the semicolon there. But at least two big issues are your check for ending the for loop - you were comparing it to the list itself not the size, and the fact that you don't do anything with the return value. Depending upon what you've done with those instances they may or may not still be there.

Code:
var num = RoomGen_GetRoomNumber(global.RoomGen_x, global.RoomGen_y);
var map = RoomGen_GetRoomMap(num);
var list = map[?"room_type_save_changes"];
if (ds_list_empty(list)) {
       ds_list_add(list, (instance_create_layer(180,300,"Instances",oStone)));
       ds_list_add(list, (instance_create_layer(300,300,"Instances",oStone)));
       ds_list_add(list, (instance_create_layer(420,300,"Instances",oStone)));

} else {
    for (var a = 0; a< ds_list_size(list); a++){ //remove the semicolon after a++, also presumably you want the size of the list not the list itself?
        ds_list_find_value(list, a); //you must do something with the value once you find it
    }
}
 

sinigrimi

Member
I cleaned up the code a little below. I'm actually surprised it compiled with the semicolon there. But at least two big issues are your check for ending the for loop - you were comparing it to the list itself not the size, and the fact that you don't do anything with the return value. Depending upon what you've done with those instances they may or may not still be there.

Code:
var num = RoomGen_GetRoomNumber(global.RoomGen_x, global.RoomGen_y);
var map = RoomGen_GetRoomMap(num);
var list = map[?"room_type_save_changes"];
if (ds_list_empty(list)) {
       ds_list_add(list, (instance_create_layer(180,300,"Instances",oStone)));
       ds_list_add(list, (instance_create_layer(300,300,"Instances",oStone)));
       ds_list_add(list, (instance_create_layer(420,300,"Instances",oStone)));

} else {
    for (var a = 0; a< ds_list_size(list); a++){ //remove the semicolon after a++, also presumably you want the size of the list not the list itself?
        ds_list_find_value(list, a); //you must do something with the value once you find it
    }
}
Thanks, for your edits, I also tried to use ds_list_size. In my case, ds_list_find does not return the line that I set, apparently this function is not able to reproduce instnance_create. It's a pity, I have been trying to find a workaround for some time, but my attempts are even, a strange problem.

P.S .: This is what ds_list sees. Just numbers ...

e0Ra6xnoLT.png
 
Last edited:

Simon Gust

Member
Just put the raw values into the list and when you read them later put them back into instance create layer. Make sure the order is right.
 

FrostyCat

Member
Instance IDs cannot be reused across different sessions or attempts to enter a room. You have to record some other less volatile reference (e.g. x-y position), and use that instead to identify destroyed instances. Alternatively, you can also consider room persistence.
 

sinigrimi

Member
I wrote something and tomorrow I’ll try it. I hope it works
Just put the raw values into the list and when you read them later put them back into instance create layer. Make sure the order is right.

Code:
if (ds_map_empty(map)){
for (var A=0; A<amount_objects; A++){
   ds_map_add(map,_id[A], "Exist")
...
...
   }
}

for (a=0; a<amount_objects;a++){
if (map[? a]=="Exist"){
      with instance_create(x,y,obj){
         ID = a;
      }
   }
}
and in obj:
Code:
if (destroy){
ds_map_replace(map,_id[ID],"Not exist");
}
 

sinigrimi

Member
I had to improve the code and I did it! Thanks to everyone who wrote the message, I really appreciate it!
 
Top