Order of function sequences

Started by Jojowl80, Fri 29/05/2020 22:37:02

Previous topic - Next topic

Jojowl80

I have a sequence where the character turns off a light switch.


Code: ags

} 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?

Crimson Wizard

#1
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

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


room B:
Code: ags

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

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
    }
}

Crimson Wizard

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.

Jojowl80

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

Crimson Wizard

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?

Jojowl80

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

//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;
    }


Crimson Wizard

Have you connected these functions to room events?

Jojowl80

well don't I feel dumb lol. I didn't even know you could do that with rooms . Problem solved, thanks a lot!

SMF spam blocked by CleanTalk