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

GameMaker Storing a previous object in a variable.

R

Ruzzle

Guest
I have a script that sets up the camera to an object:
This camera object (obj_camera) has a variable following, set's its x, y to that of the following object (following)
And the camera object has a variable for the previous followed object. (prev_follow)

Other objects can set the camera placement to another object with this script:

scr_camera_set(id,obj_camera);

GML:
var moveto_obj = argument0
var object_cam = argument1;

if (object_cam.prev_follow != object_cam.following) {
object_cam.prev_follow=object_cam.following;
}

object_cam.following=moveto_obj;
This works fine for the camera to follow an object.
But now when i run the script again with argument0 as "obj_camera.previous_following" it won't follow the previous object.

Ideally I would be able to call this script (too) to 'reset' the following object to the previous object but with this script it doesn't seem to work.
If somebody could help me with setting the camera object back to the previous following object that would be great!
 

chamaeleon

Member
I have a script that sets up the camera to an object:
This camera object (obj_camera) has a variable following, set's its x, y to that of the following object (following)
And the camera object has a variable for the previous followed object. (prev_follow)

Other objects can set the camera placement to another object with this script:

scr_camera_set(id,obj_camera);

GML:
var moveto_obj = argument0
var object_cam = argument1;

if (object_cam.prev_follow != object_cam.following) {
object_cam.prev_follow=object_cam.following;
}

object_cam.following=moveto_obj;
This works fine for the camera to follow an object.
But now when i run the script again with argument0 as "obj_camera.previous_following" it won't follow the previous object.

Ideally I would be able to call this script (too) to 'reset' the following object to the previous object but with this script it doesn't seem to work.
If somebody could help me with setting the camera object back to the previous following object that would be great!
Seems like your code would benefit from the use of show_debug_message() before you call the script and inside the script before, inside, and after the if statement, with various interesting output like values of objects/instances passed, and see what output does not match your expectation for some given call.
 

Nidoking

Member
obj_camera.previous_following
Just to be sure, you meant to say previous_follow, correct?

Also, is obj_camera the name of the object? How do you know you're referencing the correct instance?

if (object_cam.prev_follow != object_cam.following) {
object_cam.prev_follow=object_cam.following;
}
You don't need the if here. Just make the assignment. If they're already equal, it won't change anything.

What are following and prev_follow initialized to?
 
R

Ruzzle

Guest
Just to be sure, you meant to say previous_follow, correct?

Also, is obj_camera the name of the object? How do you know you're referencing the correct instance?



You don't need the if here. Just make the assignment. If they're already equal, it won't change anything.
Hi thanks for your answer, i did mean previous_follow, yes.
I copy the instance ID directly from the game room (when I double click on it) that's how i choose the correct instance.

What are following and prev_follow initialized to?
I'm sorry English isn't my main language what are you asking exactly?

Seems like your code would benefit from the use of show_debug_message() before you call the script and inside the script before, inside, and after the if statement, with various interesting output like values of objects/instances passed, and see what output does not match your expectation for some given call.
I have tried this, but I still don't exactly understand; but thanks for the tip!
 

Nidoking

Member
I copy the instance ID directly from the game room (when I double click on it) that's how i choose the correct instance.
Where is the call where you use this value?

I'm sorry English isn't my main language what are you asking exactly?
You set these variables based on existing values of these variables. What are the first values that they have before you start doing this? Where does the cycle begin?
 
R

Ruzzle

Guest
Where is the call where you use this value?
I have a trigger object and a cutscene system.
It executes like this;
Code:
cutscene_set_object(inst_3A341655,obj_camera)
And then to snap back to the previous following object
Code:
cutscene_set_object(obj_camera.previous_follow,obj_camera)
You set these variables based on existing values of these variables. What are the first values that they have before you start doing this? Where does the cycle begin?
I set up these variables in the obj_camera create event;
Code:
prev_follow=noone;
 
Last edited by a moderator:
R

Ruzzle

Guest
edit: I just realized i'm stupid, I was updating the variable in the create event so it didn't update correctly.
I had a quick nap that was the best bug fix ha!
 
Top