I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: Kyir on June 15, 2015, 01:54:45 PM

Title: Affecting Existing Objects
Post by: Kyir on June 15, 2015, 01:54:45 PM
Is there a more elegant/simple/whatever was to affect objects that already exist when something occurs other than making them all check for variables in their step events? For example: if object A and B exist, and I want to make something happen to object B when object A gets shot.

I feel like there's gotta be something, but finding it in the depths of game maker's help feature is beyond me. 
Title: Re: Affecting Existing Objects
Post by: YoSniper on June 15, 2015, 05:04:31 PM
This would have to be on a case-by-case basis, but something you could do is:

On Event in objectA when objectA gets shot:
Code: [Select]
with(objectB) {
    //React to shot
}
Title: Re: Affecting Existing Objects
Post by: Kyir on June 15, 2015, 10:47:34 PM
Would that make both objects react that way, or just Object B?
Title: Re: Affecting Existing Objects
Post by: pieceofcheese87 on June 15, 2015, 10:58:33 PM
Just to clarify, object A and object B are two of the same object?
Title: Re: Affecting Existing Objects
Post by: Kyir on June 16, 2015, 01:34:09 AM
Preferably not, but if that's what's necessary I can probably still make it work.
Title: Re: Affecting Existing Objects
Post by: YoSniper on June 16, 2015, 06:58:44 AM
Would that make both objects react that way, or just Object B?

It would not affect objectA, unless you put code outside the "with" block. However, if there are multiple instances of objectB, all of them will be affected simultaneously.
Title: Re: Affecting Existing Objects
Post by: pieceofcheese87 on June 16, 2015, 07:18:47 AM
Yeah, if they are 2 different objects then you can control all of one type by doing what yosniper said. You can also control one instance of an object with the instance_place function.
for example:
Code: [Select]
a=instance_place(x,y+32,objectA);
with(a){ hspeed=10 }
This will check for a collision with an object at 32 pixels under its origin. If it does find a collision, then the variable "a" will be replaced by that instance that it collides with.
Then, only that one instance of objectA will move to the right.

Another way to control 1 instance of an object is in a collision event, where you can use other, which means the instance it collides with.
Title: Re: Affecting Existing Objects
Post by: Kyir on June 16, 2015, 08:01:41 AM
Oh, yeah, I would have never thought of something like that. Thank you very much!