SOLVED with(other)

Hi

Checked the manual and its not clear on this. I have a WindBatObject and a BOSSesParent. My question basically is, the following piece of code:

GML:
    with(other)   //event is BOSSESParent. other is WindBatStill
    {
        hp_minus = irandom_range(200, 400)
        hp -= hp_minus
        floater = instance_create_depth(x+10, y-10, -1700, DamageIndicatorObject);
        floater.text = string(hp_minus);
        
        if (hp <= 0)
        {
            audio_play_sound(DieingBrainSound, 5, false)
        }
    }
I don't understand how with(other) functions. What I want to do is animate the BOSSesParent object. I was going to have a BOSS
on collision it is supposed to do a "bite" animation by the BOSS and then to stop after a few seconds then start again, etc.
Until the BOSS is done or the attacking character dies.

-TW
 

Nidoking

Member
with (other) functions the same way as with (anything else). It runs what's in the block from the perspective of "other". You've said that the event is BOSSESParent, which is not an event. In fact, nothing that you posted does anything with a BOSSESParent, if it is indeed within an event of BOSSESParent. If other is WindBatStill, then everything you posted affects WindBatStill and has no impact on BOSSESParent at all. The context that you haven't provided is what's going to be relevant here.
 

TheouAegis

Member
If you mean the event is COLLISION WITH BOSSesParent inside the object WindBatStill, then other is the instance of the BOSSesParent collided with.

If the event is a COLLISION WITH WindBatStill inside the object BOSSesParent (or a child of it), then other is the instance of WindBatStill collided with.

If the event is NOT a Collision Event, then that code must be inside another with() call, in which case other refers back to the instance that called with().

Code:
//Object0's Step Event:
with Object1 {
    //Object1 is running all code inside this block now
    with other {
        //Object0 instance all of this code is in is now running code inside this block
    }

    with Object2 {
        //Object2 is now running all code inside this block
        with other {
            //Object1 instance running this code is now running code inside this block
        }
    }
}

if instance_place(x,y,Object1) {
    with other  {
        //Object0 is running this code because "other" means nothing outside a Collision Event or with() call
    }
}
 
Sorry it took me so long to get back to this thread. The event is a collision with BOSSesParent in the object WindBatStill. WindBatStill is the object of the collision. I think. So other would be the instance of WindBatStill. I hope that settles it. Thanks @TheouAegis
 

TheouAegis

Member
If the code is inside the bat object, checking for a collision with the boss object, then other should refer to the boss. So your code should be lowering the boss's hp.
 
Top