Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Jojowl80 on Fri 29/05/2020 22:37:02

Title: Order of function sequences
Post by: Jojowl80 on Fri 29/05/2020 22:37:02
I have a sequence where the character turns off a light switch.


Code (ags) Select

} else if (Verbs.UsedAction(eGA_Push)) {
    player.Say("Okay.");
    player.ChangeRoom(2);
    player.Transparency = 100;
    player.Say("Oooohhhh Deeaar...");
    player.Say("I think I broke the game");
    player.Say("Jojo??");
}


but what happens is that it displays the after speech *before* the room goes dark.
is dialogue just always set to go first?
Title: Re: Order of function sequences
Post by: Crimson Wizard on Fri 29/05/2020 22:41:27
AGS cannot change room in the middle of the function, so it schedules it until a function ends.

The usual solution is to break cutscene into 2 parts, play part 1 in the room A, change room, then play part 2 in the room B's "after fade-in" event handler.

You may need to set some global variable to tell room B to play that cutscene.

For example, assuming you have global variable of type bool called PlayCutscene1:

room A:
Code (ags) Select

} else if (Verbs.UsedAction(eGA_Push)) {
    player.Say("Okay.");
    PlayCutscene1 = true;
    player.ChangeRoom(2);
}


room B:
Code (ags) Select

function Room_AfterFadeIn()
{
    if (PlayCutscene1) {
        player.Transparency = 100;
        player.Say("Oooohhhh Deeaar...");
        player.Say("I think I broke the game");
        player.Say("Jojo??");
        PlayCutscene1 = false; // don't play again
    }
}


PS. Actually, player.Transparency is better changed in event "Before fade in", because otherwise you will see player while room B is fading in.

So, room's script should be like:
room B:
Code (ags) Select

function room_Load()
{
    if (PlayCutscene1) {
        player.Transparency = 100;
    }
}

function Room_AfterFadeIn()
{
    if (PlayCutscene1) {
        player.Say("Oooohhhh Deeaar...");
        player.Say("I think I broke the game");
        player.Say("Jojo??");
        PlayCutscene1 = false; // don't play again
    }
}
Title: Re: Order of function sequences
Post by: Crimson Wizard on Fri 29/05/2020 22:47:21
Re-reading what you wrote in the first post about turning off a light switch, I don't know full details of your game, but if all you want is to make a room go dark with everything in it invisible, you may simply create a black non-clickable GUI and make it appear over room.
Title: Re: Order of function sequences
Post by: Jojowl80 on Fri 29/05/2020 23:00:50
So I put "Bool PlayCutscene1:" into the global script and got the error 'Undefined token 'PlayCutscene1' in the room 1 script
I am still very new to this.

There are a few things in the room such as eyes that still remain. the light switch is the only clickable thing, to return back to normal
Title: Re: Order of function sequences
Post by: Crimson Wizard on Fri 29/05/2020 23:19:06
Quote from: Jojowl80 on Fri 29/05/2020 23:00:50
So I put "Bool PlayCutscene1:" into the global script and got the error 'Undefined token 'PlayCutscene1' in the room 1 script
I am still very new to this.

The easiest way to create a global variable is to go to "Global Variables" node in the project tree, and add one in the table there. Then you may just use it in script (as in above example).


Quote from: Jojowl80 on Fri 29/05/2020 23:00:50
There are a few things in the room such as eyes that still remain. the light switch is the only clickable thing, to return back to normal

It's still possible to achieve this in the same room by darkening certain objects, switching background to different image, and so on. I don't know what eyes are, is this a room object, or cursor?
Title: Re: Order of function sequences
Post by: Jojowl80 on Fri 29/05/2020 23:41:51
ya I have room 1 and room 2 ( which is darkened)

I put the global Variable in, it accepted it and went into the game. Now the cutscene functions for room 2 are not working.
this is the code I put in as suggested.

Code (ags) Select

//room1

function hlightswitch_AnyClick()
{
if (Verbs.UsedAction(eGA_WalkTo)) {
}
else if (Verbs.UsedAction(eGA_Push)) {
    player.Say("Okay.");
    PlayCutscene1 = true;
    player.ChangeRoom(2);
}
//room2


function room_Load()
{
    if (PlayCutscene1) {
        player.Transparency = 100;
    }
}

function Room_AfterFadeIn()
{
     if (PlayCutscene1) {
       
        player.Say("Oooohhhh Deeaar...");
        player.Say("I think I broke the game");
        player.Say("Jojo??");
        PlayCutscene1 = false;
    }

Title: Re: Order of function sequences
Post by: Crimson Wizard on Sat 30/05/2020 00:15:42
Have you connected these functions to room events?
Title: Re: Order of function sequences
Post by: Jojowl80 on Sat 30/05/2020 00:33:22
well don't I feel dumb lol. I didn't even know you could do that with rooms . Problem solved, thanks a lot!