• 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!

GML One Object Instance Change HELP "GML Code"

I

im_yonkara

Guest
So what I'm trying to do is make a "peg" object start its sprite animation when another "Ball" collides with it. There are multiple duplicated "peg"s around the screen, but when one collides with the "Ball" every "peg" on screen starts the animation. I would like to make each individual instance/ copy of the "peg" blink/ change sprite animation speed, any help would be appreciated.
The code is just a simple collide and then change sprite speed btw.

Pretty new to GML, but I do know other languages so its kind of hard to figure out how to do this when I'm so new to this interface, so if possible make the reply or answer light and easy to follow if you don't mind.
 

FrostyCat

Redemption Seeker
You need to learn the difference between an object and an instance.
NEVER access a single instance by object ID if multiple instances of the object exist. This includes attempts to reference or set object.variable (which is inconsistent across exports) and using with (object) to apply actions to it (this encompasses all instances of the object instead of just the one you want). Verbally, "Dog's colour" makes sense with one dog, but not with multiple dogs.
Collision-checking functions: instance_place() and instance_position() are the instance-ID-oriented analogues of place_meeting() and position_meeting(). Functions that start with collision_ all return instance IDs. Save that instance ID into a variable (e.g. var inst_enemy = instance_place(x, y, obj_enemy);), then use that as the subject to work with (e.g. inst_enemy.hp -= 10;). Note that these functions return noone upon not finding a collision. Always account for this special case whenever you handle collisions this way.
 
Top