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

Windows Reference/check all instances of an object individually

F

Fluke

Guest
So I have a horizontal scroller shooter and when the enemies pass the player on the left, I want them to carry on going. At the moment, the enemies head towards the player as intended from the right. However, once one reaches the left side of the player, all stop moving towards the player and go straight left until the ones to the left of the player are destroyed. I know it has something to do with referencing each instance of the object individually, I just don't know how to do that. Help would be appreciated, thanks.

This is the code I am using as of now (Player is Aircraft1 and enemy is LondonAir):

var dir
if instance_exists(obj_Aircraft1)
{
dir=point_direction(x, y, obj_Aircraft1.x, obj_Aircraft1.y)
//If player is to the right
if (obj_Aircraft1.x>obj_LondonAir.x){
speed=7;
direction=180;
shoot=0;

}
if (obj_Aircraft1.x<obj_LondonAir.x){
speed=7
direction=dir
}
alarm[0]=room_speed
};​
 

FrostyCat

Redemption Seeker
Learn the difference between objects and instances. Particularly, if that code is in obj_LondonAir, these quotes from the article apply to you:
Corollary: NEVER set or use an instance's own variables with object.variable. An instance's own variables can be referenced as-is without dot prefixes. DO NOT use self. If multiple instances of the object exists, you might end up setting the value for all instances or for some other instance (depending on the export).
An instance's own variables: Type out the variable name as-is, without any dot-prefixes. DO NOT use self. DO NOT use the object ID.
 
F

Fluke

Guest
Fixed, thanks for you quick reply. Was just me being a moron. Just took out obj_LondonAir before .x and everything worked fine.
 
Top