Jump to content


Photo

change nearest instance


  • Please log in to reply
3 replies to this topic

#1 rustyredline

rustyredline

    GMC Member

  • New Member
  • 8 posts

Posted 10 August 2010 - 09:38 AM

I'm trying to make a level of a game i'm making just like the classic arcade/sega game bombjack. 1 bomb is ignited but the rest are unlit. when you collect the ignited bomb the nearest unlit should then become ignited, I tried making 2 objects 1 for the lit bomb one for unlit but im struggling with code to make this work, can anyone help me to change instance to nearest object with code I have tried this...

execute_code for object_unlit
instance_nearest(x, y, object_unlit);
instance_change(object_bomb,0);

but it just makes all the unlit bombs become lit

or this...
execute_code for object_unlit
instance_nearest(x, y, object_unlit);
instance_change(object_bomb,0);
but it just makes the lit bomb turn back into itself before its destroyed so basically the bomb is uncollectable just there forever!

Edited by rustyredline, 10 August 2010 - 09:40 AM.

  • 0

#2 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 10 August 2010 - 09:54 AM

can anyone help me to change instance to nearest object with code I have tried this...

That "instance_nearest(...)" command returns the ID of the nearest instance. You have to use that result to act upon that instance.

The way you have it now the "instance_nearest(...)" command does not do anything ...

Try this :
with instance_nearest(x, y, object_unlit) {
  instance_change(object_bomb,0);
}

  • 0

#3 rustyredline

rustyredline

    GMC Member

  • New Member
  • 8 posts

Posted 10 August 2010 - 10:04 AM

can anyone help me to change instance to nearest object with code I have tried this...

That "instance_nearest(...)" command returns the ID of the nearest instance. You have to use that result to act upon that instance.

The way you have it now the "instance_nearest(...)" command does not do anything ...

Try this :
with instance_nearest(x, y, object_unlit) {
  instance_change(object_bomb,0);
}

wow you've just done for me in a few seconds what ive been trying to do for weeks . I cannot thank you enough when my game becomes famous i will credit you ragrnak thank you
  • 0

#4 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 10 August 2010 - 10:17 AM

wow you've just done for me in a few seconds what ive been trying to do for weeks . I cannot thank you enough when my game becomes famous i will credit you ragrnak thank you

I've probably been programming in GM a bit longer than you, so I blame it on experience (something you will get soon enough). :)

And although not required I allways like seeing myself in the credits, thanks.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users