GMS 2.3+ Need help with changing objects when ship is spawned

So my camera setup is set to follow the starbase at the moment. I'm just wondering how I can add some code so that when the ship(obj_Aura2) is spawned, my target will change from the base to the ship spawned.
Camera.JPGAura Docked.JPG
 

FoxyOfJungle

Kazan Games
target = obj_Aura2 ?

Try: camera_set_view_pos()
It all depends on how your camera is programmed, you must update the camera's position on the step, so just change the target.
 
target = obj_Aura2 ?

Try: camera_set_view_pos()
It all depends on how your camera is programmed, you must update the camera's position on the step, so just change the target.
Okay so in the obj_camera. In a step event. Something like:

if instance_exists(obj_Aura2){
target = obj_Aura2;
}

Something like that?
I'll try.
 
The more important detail you left out is HOW the ship(obj_Aura2) is spawned. When you do that, is something preventing you from setting the camera's target to the id of the newly-spawned instance?
Yeah I suppose I could try using the step event in the button that spawns the ship. Never thought of that. If that's what you mean.
 

Nidoking

Member
step event in the button
If you're spawning the ship by checking for mouse clicks in the step event, then yes, that makes sense. If you're using a Click Event, then you would put it there. In short, the best place to put code that runs when something changes is in the place where the change happens. When the ship spawns, that's when you do EVERYTHING that should happen when the ship spawns. Having objects sit out there and monitor for conditions to change can work, but it generally isn't the best way to do things.

It's also much easier that way to use an instance id, since you just spawned the ship and you know what the instance id is, rather than trying to use the object id as suggested here. If there's only ever one instance of any given object at a time, the object id can be used that way, but I think using instance ids is just better for that in general.
 
If you're spawning the ship by checking for mouse clicks in the step event, then yes, that makes sense. If you're using a Click Event, then you would put it there. In short, the best place to put code that runs when something changes is in the place where the change happens. When the ship spawns, that's when you do EVERYTHING that should happen when the ship spawns. Having objects sit out there and monitor for conditions to change can work, but it generally isn't the best way to do things.

It's also much easier that way to use an instance id, since you just spawned the ship and you know what the instance id is, rather than trying to use the object id as suggested here. If there's only ever one instance of any given object at a time, the object id can be used that way, but I think using instance ids is just better for that in general.
Thanks for explaining that to me. So I group objects in my instances though. I'm thinking it saves on memory or something? You're saying maybe I should have one object per instance so I can call them individually from the Instance id?
 
The problem also is that when that button is clicked.(It's setup with a "left down" event) it is destroyed along with the menu box it sits in. I don't know if the step event would run that command after the instance is destroyed?
 

Nidoking

Member
You're saying maybe I should have one object per instance so I can call them individually from the Instance id?
No. You don't seem to understand the difference between objects and instances. You use instance IDs so that you don't NEED separate objects for every instance.

I don't know if the step event would run that command after the instance is destroyed?
In what way is running a step event in a button relevant to what you're doing? Your responses in this thread are demonstrating a lack of understanding of some very fundamental aspects of Game Maker. I think you may need to do some more basic tutorials and learn the simple things before you try to do anything complicated.
 
Top