Jump to content


Photo

Getting Object Index With Variable?


  • Please log in to reply
1 reply to this topic

#1 Reshure

Reshure

    Reshure

  • New Member
  • 320 posts

Posted 06 June 2007 - 06:47 PM

I got 1 object (object1) with 3 instances. Every instance has in his creation code (in the room editor) a variable named wid. Object1 creates object2 with this code:
obj = instance_create(x,y,object2);
obj.wid = wid;
I have this code in the step event of object2. Object2 moves.

Object2:
if wid == object1.wid
{
if distance_to_object(object1) > 200
{
instance_destroy();
}
}
But it never destroys himself because my three instances haves a 100 pixel gap between them. I need to get the object index of the instance with the same wid.

Thank you. :lol:

Edited by Gnss, 06 June 2007 - 06:47 PM.

  • 0

#2 Falconer

Falconer

    GMC Member

  • New Member
  • 79 posts

Posted 06 June 2007 - 07:18 PM

I think that the problem is that object2 doesn't know what object1.wid is (you never gave object2 object1's id for it to check with).

Try this

object2 create event
variable_name = instance_nearest(x,y,object1)
object2 step event
if wid == variable_name.wid
{
if distance_to_object(object1) > 200 // you might try changing the object1 here to your variable
{
instance_destroy();
}
}

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users