S
Sethis
Guest
Hi guys,
I'm currently working on a little side project (an endless runner) but I'm stuck (since almost 3h now) because of something that I can't wrap my head around. Maybe someone else might spot what I might overlooked, so here I am, asking for help.
First, I have a script that store in a 2D array the x, y, and name (get_object_name) of every obj_obstacle in the room.
It's saved in the globalvar array named "room_array_test".
Then, in an other room, I want to recreate every instances of the obj_obstacle at the same position. I have a controler object (obj_processor) who do that in a create event :
Problem : it's not working, though the show_message give me the good name (either obj_square or obj_bigSquare). Seems like it's coming from the third argument of instance_create, cause I meddled with it (tried with a specific object like obj_square (which works) and "obj_square" (which doesn't).
I found a workaround, but it's just an ugly way of doing things, and I want to understand why it didn't works the first time :
Anyone ?
Thanks in advance for taking the time to help me.
I'm currently working on a little side project (an endless runner) but I'm stuck (since almost 3h now) because of something that I can't wrap my head around. Maybe someone else might spot what I might overlooked, so here I am, asking for help.
First, I have a script that store in a 2D array the x, y, and name (get_object_name) of every obj_obstacle in the room.
Code:
/// Count how many instance there is in the room and store them (with their position) in an array
var i;
var current_instance;
// Store every instance in a 2D array (x [i,0] , y [i,1]), obj type [i,2]
for (i = 0; i < instance_number(obj_obstacle); i++) {
current_instance = instance_find(obj_obstacle,i);
portion_storage[i,0] = current_instance.x;
portion_storage[i,1] = current_instance.y;
portion_storage[i,2] = object_get_name((current_instance).object_index); // Object type (= name, ex: "obj_square") (it's a string)
}
return portion_storage;
It's saved in the globalvar array named "room_array_test".
Then, in an other room, I want to recreate every instances of the obj_obstacle at the same position. I have a controler object (obj_processor) who do that in a create event :
Code:
for (i = 0; i < array_height_2d(room_array_test); i++) {
show_message(room_array_test[i,2])
instance_create(368+room_array_test[i,0],room_array_test[i,1],room_array_test[i,2]);
}
Problem : it's not working, though the show_message give me the good name (either obj_square or obj_bigSquare). Seems like it's coming from the third argument of instance_create, cause I meddled with it (tried with a specific object like obj_square (which works) and "obj_square" (which doesn't).
I found a workaround, but it's just an ugly way of doing things, and I want to understand why it didn't works the first time :
Code:
for (i = 0; i < array_height_2d(room_array_test); i++) {
show_message(room_array_test[i,2])
if room_array_test[i,2] == "obj_square" {
instance_create(368+room_array_test[i,0],room_array_test[i,1],obj_square);
}
else if room_array_test[i,2] == "obj_bigSquare" {
instance_create(368+room_array_test[i,0],room_array_test[i,1],obj_bigSquare);
}
else {
instance_create(368+room_array_test[i,0],room_array_test[i,1],obj_trigger);
}
}
Anyone ?
Thanks in advance for taking the time to help me.