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

how to reference to an objects coordinates using its id?

C

chandleroca

Guest
Hi so ive set that when my object (arrow) collides with another object (zombie) the arrow will get the zombies id. and store it in a variable named "store". But how do I use the id to locate the zombie. I want to make the arrow to be fixed into the collided zombie's coordinates.
I used this:

with (store)
{
// what should I put here???
}
 
W

whale_cancer

Guest
If 'store' holds the id of the instance, you can simply use store.x and store.y to reference its coordinates.
 
C

chandleroca

Guest
ok ok lemme try it. Sorry im experimenting with basic codes and I just discovered about id's and "this. "
 
W

whale_cancer

Guest
ok ok lemme try it. Sorry im experimenting with basic codes and I just discovered about id's and "this. "
No worries.

FYI, you use 'with' to execute code as if from inside the instance you are referencing. You _could_ use that to get the coordinates, but it would be convoluted and not a good method at all.
 
If you would like that arrow to stick into the zombie only after it has collided, you can do something like:

In the arrow's create event, initialize store as noone.
We do this so we can use checks when working with the variable.
Code:
store = noone;
In the arrow's collision event with zombie:
Code:
if(store == noone){ //only want to stick to something if we have not stuck to anything else
  store = other;
}
In the arrow's step event:
Code:
if(store != noone){ //stick to an object only if we have actually collided with something
  x = store.x;
  y = store.y;
}
 
Top