[SOLVED] instance_change - which event do I use it in?

E

EricR175

Guest
Hi,

I'm trying to spawn a new object when another is destroyed. I'm trying to use instance_change but I've tried everything. I've tried using it in each event that I have created...but no luck yet. I have a destroy event that destroys two objects. One I want to keep destroyed but I want the other to change into a different object.

Any help would be appreciated. Meanwhile, while I wait for an answer, I'll keep trying different things.

Thanks!

BTW....I'm using Gamemaker Studio 2
 
Last edited by a moderator:
A

Aura

Guest
Post the code. Why are you using a Destroy event to destroy two more instances? Elaborate a bit on that.
 

sp202

Member
I've heard it's bad practice to use instance_change, you're better off destroying and creating instances instead. So you'd place an instance_create either after the instance_destroy or in the destroy event of the object being destroyed.
 
E

EricR175

Guest
Post the code. Why are you using a Destroy event to destroy two more instances? Elaborate a bit on that.
I'm destroying two events when they collide.

I'm destroying two objects when they collide......

instance_destroy(); //destroy self
with(other) instance_destroy(); //destroy other object

I want the "other" to turn into another object on collision
 
E

EricR175

Guest
i'm new to all of this. I read that it was useful for what I was trying to acheive.
 
E

EricR175

Guest
I'm trying to destroy one object and have the new one appear in the exact same x,y position the other disappeared from.
 
D

dj_midknight

Guest
What I would do is in your with(other) code something along the lines of

var x = other.x;
var y = other.y;
instance_destroy(other);
instance_create(x,y,NEW TYPE);

This will destroy the current object and create a new object of the requested type in the location of the destroyed object.
 
E

EricR175

Guest
thanks djmidknight. I'll give it a try and let you know if it worked.
 
E

EricR175

Guest
This is what I changed it to...

var lgasteroidx = obj_asteroids.x
var lgasteroidy = obj_asteroids.y
instance_destroy(); //when hit by missile
with(other) instance_destroy(); //when collides with other objects
instance_create_layer(lgasteroidx, lgasteroidy, Instances, obj_smasteroids); //create obj in the Instances layer

This is a collision event of obj_asteroids and the Instances layer does already exist.
Since I am using Gamemaker 2 I could only find instance_create_layer and not instance_create. I'm assuming that in gamemaker 2 that was changed for some reason.

Error...
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Eventobj_bullet
for object obj_asteroids:

Variable <unknown_object>.Instances(100004, -2147483648) not set before reading it.
at gml_Object_obj_asteroids_Collision_8b39497d_175f_435e_95b8_811c06c7c15f (line 6) - instance_create_layer(lgasteroidx, lgasteroidy, Instances, obj_smasteroids);
############################################################################################
 
E

EricR175

Guest
Yes I read that but...

when I use instance_create and compile to test, the same error comes up...

unknown function or script instance_create

When I use instance_create_layer I have no issues except for the one described above. Works all other times.

When I search the manual, there is no instance_create.

Also when I type instance_create in a script, it doesn't turn the correct color to let you know that you have used the syntax correctly. In GM 2 it turns orange-ish when you type it correctly. It turns a grey-ish color if incorrect.
 
Last edited by a moderator:

sp202

Member
Yeah, it turns out instance_create has been replaced by instance_create_depth and instance_create_layer, so use whichever you feel is more appropriate.
 
D

dj_midknight

Guest
So if I am reading this correctly it is not able to find the object(layer) known as instances being passed into the create function and is basically telling you "hey I cant read what isnt there". So I dont use GMS 2 yet and cant give you a perfect answer to this, but it seems like you need to grab the ID of the layer and pass that for this to work.
 
When using instance_create_layer you either give it the id or the name. It looks like you want to give it the name Instances, however the name is supposed to be enclosed in "". So you want to put:
Code:
instance_create_layer(lgasteroidx, lgasteroidy, "Instances", obj_smasteroids);
 
Top