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

Multiple instance for multiple instance

M

Maxdax5

Guest
Hello Hello!

So the thing i got a hard time to deal with is; I made an enemy tank who have a turret. I made a spawn point but there is only one who have a turret. I know my problem witch is that the turret spawn on "obj_enn_tank1" but then when an other "tank" spawn, the turret is already placed.

Solution: if a new tank spawn, add 1 to its value (change id) (or something)(hahaha)

thx in advance!
 

Bingdom

Googledom
It can easily be achieved by doing something like this:
TANK CREATE EVENT
Code:
turret = instance_create(x,y,obj_turret);
turret.creator = id;
TURRET END STEP EVENT
Code:
x = creator.x;
y = creator.y;
 
M

Maxdax5

Guest
waow! thx a lot! I dont understand a lot how to play with id yet. knew that was my problem tho. thx again! ^^
 
M

Maxdax5

Guest
ok so i tryed to use a bit more the "creator" idea and here is something i dont understand:
SHELL_CREATE_EVENT
maxrange = creator.maxrange;

SHELL_STEP_EVENT
if point_distance(x,y,creator.x,creator.y) > maxrange {
instance_destroy()
}

it dont know what is the "maxrange" but it does know who the creator is... any idea? (creator maxrange = 500)
 

Bingdom

Googledom
The create event occurs before the newly assigned variables get applied. So the bullet would be reading from a non-existent object
You need to set those variables as you are creating the bullet.

A problem with your current range setup is that the bullet would last longer if the tank goes with the bullet, and you would have less range if you go against the bullet.
Instead, use an alarm.
 
M

Maxdax5

Guest
no, the game just wont start and saying it dont know what (creator.maxrange) is. i am not concentrate on this for now but i'll be looking it for sure since that make a probleme for not only the shell range.
 

Perseus

Not Medusa
Forum Staff
Moderator
That's what @Bingdom is talking about. When the Create event of the bullet instance runs, it doesn't know what creator is. The code runs this way:
Code:
bullet = instance_create(x, y, obj_bullet);
// The Create event of instance "bullet" gets triggered here
bullet.creator = id;
Since the Create event runs before creator is even declared for the said instance, it doesn't know what creator is, so GM throws an error message. Declare maxrange when the bullet instance is created instead of using the Create event.
Code:
bullet = instance_create(x, y, obj_bullet);
bullet.creator = id;
bullet.maxrange = maxrange;
But that might not be what you want. If the tank moves with the bullet and it stays within the range, it won't get destroyed. If you want the bullet to travel 500 pixels, do this instead:
Code:
if (point_distance(x, y, xstart, ystart) > maxrange) {
   instance_destroy();
}
 
Top