Object animation after scene change

In my game I inserted two lamps with the light off-on animation when the character collides and I press the Z key I inserted the global variables for the change of scene now when I turn on one of the two lamps then I change scene and return to the first scene the both lamps are on when I have only one on, how can I make only the chosen lamp remain on?

I guess you could give the chosen lamp a variable number or name that will differentiate it from the other lamp.
Something like Lampada text variable = “LampUno”
Then the second lamp = “LampDos”
Then you can set each their own separate global variable.

1 Like

I’ll try to do it like this. Thank you.

Hi, I tried as you said but I can’t recall the object variables and store them in a global variable. Can you send me some screenshots.
Image one is the two lamps of the same sprite when I turn one on I would like the one I chose to remain after the change of scene or both

.

Hello there!

If i understand correctly, you want to save if a lamp is on or off, so that when you return to the scene, the lamp is either on or off as you left it.

Things like this can only be done by saving them into “Global Variables”, global variables are the “memory” of your game.

So to make something like this happen for example, you can do something like:
Condition
Key “a” is pressed

Action
Change global boolean variable “LampLight” to “True”

Then on a diferent event have…
Condition
Global boolean variable “LampLight” is “True”

Action
“Turn on the light”

That way when ever you return, the light will be on.
To turn it off, do the same thing, but for turning off the light, like…

Condition
Global boolean variable “LampLight” is “False”

Action
“Turn off the light”

Everything that revolves around saving things between scene changes will always be done with global variables, remenber that.

1 Like

Here you go. Tested and working on my end.

It can probably be optimized further, especially if you have a lot of lamps going on. Maybe look into putting them into an array type variable. I haven’t had much experience with such variable type though, so I’d be of little help.
But if you just have a small handful of lamps, this setup should work.

1 Like

Ok, Thank you very much :smiley:

Thank you very much :smiley:

1 Like