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

using with() with a object I'm colliding with.

I

itai singer

Guest
hi, thanks for viewing my thread.
I made in my game a kind of poison puddle and i want that every time it collides with an object, if the object's variable is_character = true it will poison him.
so here is what i got so far:

if (place_meeting(x,y,all))
{
if(other.is_char)
{
other.poison = 10;
}

}

notice that i know "other" would not work here. so the question is, how can i do code with the object the poison is colliding with?

p.s.: is know i can just use the collide event but that means that i will need to have separate event for each char object, and im sure there is a better way.
 

Simon Gust

Member
hi, thanks for viewing my thread.
I made in my game a kind of poison puddle and i want that every time it collides with an object, if the object's variable is_character = true it will poison him.
so here is what i got so far:

if (place_meeting(x,y,all))
{
if(other.is_char)
{
other.poison = 10;
}

}

notice that i know "other" would not work here. so the question is, how can i do code with the object the poison is colliding with?

p.s.: is know i can just use the collide event but that means that i will need to have separate event for each char object, and im sure there is a better way.
I guess if it works for you you could make a parent object for all character objects and have the collision event target the parent object.
Or this
Code:
var char_inst = instance_place(x, y, all); // instance place returns the id (or noone for no collision) which is required for this to work.
if (char_inst != noone)
{
 if (char_inst.is_char)
 {
  char_inst.poison = 10;
 }
}
I must say though, with a lot of objects, this may get very inefficient. The collision will go through every object to find the right one.
 
W

wakemasta

Guest
Try using instance_place(x, y, all) instead of place_meeting(x, y, all). instance_place() returns the id of the object that instance that is colliding, so you can use that id to poison your character.
 
I

itai singer

Guest
thanks a lot! creating a parent object sounds nice.


I guess if it works for you you could make a parent object for all character objects and have the collision event target the parent object.
Or this
Code:
var char_inst = instance_place(x, y, all); // instance place returns the id (or noone for no collision) which is required for this to work.
if (char_inst != noone)
{
 if (char_inst.is_char)
 {
  char_inst.poison = 10;
 }
}
I must say though, with a lot of objects, this may get very inefficient. The collision will go through every object to find the right one.
 
I

itai singer

Guest
Try using instance_place(x, y, all) instead of place_meeting(x, y, all). instance_place() returns the id of the object that instance that is colliding, so you can use that id to poison your character.
it worked! thanks a lot man! made my day.

may god bless you with male sons.
 
Top