Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: AndreasBlack on Sun 15/05/2022 09:41:36

Title: Room resets the BG when leaving the room
Post by: AndreasBlack on Sun 15/05/2022 09:41:36
I have two bakground images one with Lights and one without, so to flip the light switch in the room, i obviously call "SetBakgroundframe(1)", etc.
Everything was working fine, until i realised that the light keeps resetting itself when leaving the room.
So obvious would be to put something in "leaves room" i suppose, tried that, no success. or "Room load".


I've tried various codes, but they all come down to the same outcome visually, which is that for a microsecond the lights are the "standard state when loading the room with SetBakground" and then changes back to the correct BG image (Lights on=true/false), which is obviously not what i want.

This was my last try in the globalscripts repeatedly_execute_always()



Code (ags) Select

if (player.Room==1 && Lights_On==false)
{
   SetBackgroundFrame(0);
}


else if (player.Room==1 && Lights_On==true)
{
   SetBackgroundFrame(1);
}





Title: Re: Room resets the BG when leaving the room
Post by: Matti on Sun 15/05/2022 11:05:25
The manual says "The frame lock is released when the game changes rooms." so this is normal behavior.

Putting SetBackgroundFrame(); in room_load should work though, because it sets the background before the screen fades in. You should try that (again) and post your code in case it really doesn't work.
Title: Re: Room resets the BG when leaving the room
Post by: AndreasBlack on Sun 15/05/2022 12:33:50
Jesus, that was the first thing i've tried and i think the screen flickered between the two frames?! I must have done something to mess up the code that i did not notice last night (laugh) Thanks anyways! Nothing wrong with the code itself that's posted, just where it's placed in the room. Beginners take notice :)
Title: Re: Room resets the BG when leaving the room
Post by: Khris on Tue 17/05/2022 12:31:20
This should be enough:
Code (ags) Select
function room_Load() {
   SetBackgroundFrame(Lights_On); // bool becomes 0 or 1
}
Title: Re: Room resets the BG when leaving the room
Post by: AndreasBlack on Tue 17/05/2022 14:12:21
Thanks Khris!