• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[HELP] 'instance_create' not working

P

Phocoena Studio

Guest
Hi

What I'm trying to do here, is when player open the pack by clicking obj_open,

it moves to rm_packopen from rm_packs, then I want to create the according pack that player wanted to open,

so basically i have four packs, i have one obj_pack with 4 image in the sprite, i have one obj_open.

But somehow, when I moved to rm_packsopen, It doesn't create obj_pack.


Object \ obj_open \ Left Released:


switch(interimpacktype){


case 1:{if (packno_1 > 0)

{
packno_1 -= 1;
room_goto(rm_packsopen);
packopentype[0] = 1;
instance_create(room_width/2, room_height/2, obj_pack)
}
break;
}

case 2:{ ....(basically the same with above)


Object \ obj_pack \ Create:


if (packopentype[0] = 1)
{
image_index = 0;
packopentype[0] = 0;
}
if(...the same



Rooms \ rm_packs \ obj_open creation code (for pack type 1):

interimpacktype = 1;
 
P

ph101

Guest
its very hard to understand your intentions here but I cn say if you have the code room_goto GM will instantly switch to the other room and not execute your other code below that (in your case 1) - because it has switched room, unless you have persitant objects, so it wont be executing your create code.
 
Last edited by a moderator:
P

Phocoena Studio

Guest
its very hard to understand your intentions here but I cn say if you have the code room_goto GM will instantly switch to the other room and not execute your other code below that (in your case 1) - because it has switched room, unless you have persitant objects, so it wont be executing your create code.
Thanks for the answer.

Then what should I do if I want to create object after switching room?

Thanks
 
S

StuffandThings85

Guest
are you using GMS 1.4 or 2? "instance_create" has been changed to "instance_create_layer" in GMS2.
 
P

ph101

Guest
Then what should I do if I want to create object after switching room?
You have some options. You could make the room spawn the object, either in the creation code or using the editor. That is only useful If it always has that object in it. Or you could set a global variable that is checked in the creation code and if that is flagged it creates the object in the room creation code. Or you could examine why you want to change room anyway and maybe realise you dont need to change room and just spawn your object in current room. Another option would be to make the open object a persitent object by clicking that tick box which I think would mean it would continue to exist and so execute the code in the new room. It all depends on what you need really, it's impossible for me to say what is the best approach though. Easiest is probably the last choice.
 
Last edited by a moderator:
P

Phocoena Studio

Guest
You have some options. You could make the room spawn the object, either in the creation code or using the editor. That is only useful If it always has that object in it. Or you could set a global variable that is checked in the creation code and if that is flagged it creates the object in the room creation code. Or you could examine why you want to change room anyway and maybe realise you dont need to change room and just spawn your object in current room. Another option would be to make the open object a persitent object by clicking that tick box which I think would mean it would continue to exist and so execute the code in the new room. It all depends on what you need really, it's impossible for me to say what is the best approach though. Easiest is probably the last choice.
Thank you for the reply.

Now I have succeeded spawning object, but i need to set image_speed = 0, and i have to set image_index according to what button user pressed beforehand. I have variable 'interimpacktype'.
 
W

Wraithious

Guest
i need to set image_speed = 0, and i have to set image_index according to what button user pressed beforehand
That stuff should be set in the creation event of the object, with the image_index set from a global variable not a local variable, hope that helps
 

NightFrost

Member
You can do it during instance creation
Code:
with(instance_create(room_width/2, room_height/2, obj_pack)){
    image_speed = 0;
    // Other necessary commands here
}
If you're still using the switch from your earlier code fragment, you also already know what interimpacktype value is and can set image_index accordingly.
 
P

Phocoena Studio

Guest
That stuff should be set in the creation event of the object, with the image_index set from a global variable not a local variable, hope that helps
Thank you so much.. I don't understand why I could not think of that...haha
Thanks guys!!!
 
Top