Author Topic: Affecting Existing Objects  (Read 1738 times)

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
  • Playstyle: Keyboard
Affecting Existing Objects
« 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. 

YoSniper

  • Awexome
  • Global Moderator
  • Spike Dodger
  • Posts: 142
  • People regard me as a programming overlord.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
    • My YouTube
  • Playstyle: Keyboard
Re: Affecting Existing Objects
« Reply #1 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
}
I don't traverse the forums as much anymore. Follow me on Twitter if you want to keep tabs on me!

Twitter: @YoSniperGames
Twitch: yosniper

Streams happen whenever I feel like it.

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
  • Playstyle: Keyboard
Re: Affecting Existing Objects
« Reply #2 on: June 15, 2015, 10:47:34 PM »
Would that make both objects react that way, or just Object B?

pieceofcheese87

  • Global Moderator
  • The Kid
  • Posts: 346
  • Personal Text
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
    • Twitch Tv Channel
  • Playstyle: Keyboard
Re: Affecting Existing Objects
« Reply #3 on: June 15, 2015, 10:58:33 PM »
Just to clarify, object A and object B are two of the same object?
Signature

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
  • Playstyle: Keyboard
Re: Affecting Existing Objects
« Reply #4 on: June 16, 2015, 01:34:09 AM »
Preferably not, but if that's what's necessary I can probably still make it work.

YoSniper

  • Awexome
  • Global Moderator
  • Spike Dodger
  • Posts: 142
  • People regard me as a programming overlord.
  • OS:
  • Linux Linux
  • Browser:
  • Chrome 43.0.2357.93 Chrome 43.0.2357.93
    • View Profile
    • My YouTube
  • Playstyle: Keyboard
Re: Affecting Existing Objects
« Reply #5 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.
I don't traverse the forums as much anymore. Follow me on Twitter if you want to keep tabs on me!

Twitter: @YoSniperGames
Twitch: yosniper

Streams happen whenever I feel like it.

pieceofcheese87

  • Global Moderator
  • The Kid
  • Posts: 346
  • Personal Text
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
    • Twitch Tv Channel
  • Playstyle: Keyboard
Re: Affecting Existing Objects
« Reply #6 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.
Signature

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
  • Playstyle: Keyboard
Re: Affecting Existing Objects
« Reply #7 on: June 16, 2015, 08:01:41 AM »
Oh, yeah, I would have never thought of something like that. Thank you very much!