Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Lurch on Sun 11/02/2018 21:41:15

Title: Cutscene (changeroom) in the middle of a dialogue
Post by: Lurch on Sun 11/02/2018 21:41:15
hi everyone, ags newbie here.

i tried reading the manual and browsing the forum but i couldn't found a solution to my problem, so i figured i'd ask directly.

what i'd like to do is "change room" while a dialogue is running. not at the beginning or at the end of a dialogue option, but in between.
the "room" is actually just a single picture. it's like a cutscene, but no animations or anything, just the pic.

i tried writing something like this in the dialogue script:

Code (ags) Select

@2
Characterone: blah blah blah
Charactertwo: blah blah
player.Changeroom(9); <-- that's the "cutscene" room
Wait(35);
player.Changeroom(4, 400, 400); <-- that's the previous room, the player is supposed to go back to where he was during the first part of the dialogue
Characterone: blah blah


unfortunately, that doesn't seem to work.

should i write a function in the global script or in the room script instead? i'm totally clueless right now. any help will be greatly appreciated!



Title: Re: Cutscene (changeroom) in the middle of a dialogue
Post by: Crimson Wizard on Sun 11/02/2018 23:40:31
Hello.

Unfortunately AGS does not support changing rooms in the middle of a script function, only in the end.
So, the only solution is to split the script in parts (or dialogs - in this case).

1. Play the dialog part #1.
2. Change to "cutscene" room 9.
3. After finishing cutscene in room 9, change back to room 4.
3. Upon entering room 4, start dialog part #2.
4. and so on.

Since you revisit same rooms several times under different circumstances, you need to introduce a condition, that would tell you when you need to start a dialog and when not.

For example, you could create a global variable called "int InCutscene;" (or rather use more descriptive name, since you game may have many cutscenes).
In the first dialog you set it up:
Code (ags) Select

@2
Characterone: blah blah blah
Charactertwo: blah blah
InCutscene = 1; <--- set variable
player.Changeroom(9); <-- that's the "cutscene" room
stop <---- end the dialog


In the room's 9 "After fade-in" event do:
Code (ags) Select

// room 9
function room_AfterFadeIn()
{
    if (InCutscene == 1)
    {
        // play cutscene
        InCutscene = 2; // update variable
        player.Changeroom(4, 400, 400); <-- that's the previous room, the player is supposed to go back to where he was during the first part of the dialogue
    }
}


And in the room's 4 "After fade-in" event you launch the following part of the dialog:

Code (ags) Select

// room 4
function room_AfterFadeIn()
{
    if (InCutscene == 2)
    {
        dDialogPart2.Start(); // launch second part of dialog
    }
    else
    {
        // something else
    }
}
Title: Re: Cutscene (changeroom) in the middle of a dialogue
Post by: Kumpel on Mon 12/02/2018 10:22:29
What about simply changing the room's background frame or putting an object in the size of the screen in front of everything? Wouldn't that suffice too? (Me trying to think practical...)
Title: Re: Cutscene (changeroom) in the middle of a dialogue
Post by: Crimson Wizard on Mon 12/02/2018 13:50:10
Quote from: Kumpel on Mon 12/02/2018 10:22:29
What about simply changing the room's background frame or putting an object in the size of the screen in front of everything? Wouldn't that suffice too? (Me trying to think practical...)

Depending on how cutscene room looks like, that could work in simplier cases, I guess. The solution I mentioned above is the for the general case when you cannot simply reconfigure current room: you may also have to add/remove objects, change walkable areas and so on, also cutscene may take place in the rooms where you normally play the game.
Title: Re: Cutscene (changeroom) in the middle of a dialogue
Post by: Lurch on Wed 14/02/2018 13:28:12
Quote from: Crimson Wizard on Sun 11/02/2018 23:40:31
Hello.

Unfortunately AGS does not support changing rooms in the middle of a script function, only in the end.
So, the only solution is to split the script in parts (or dialogs - in this case).

1. Play the dialog part #1.
2. Change to "cutscene" room 9.
3. After finishing cutscene in room 9, change back to room 4.
3. Upon entering room 4, start dialog part #2.
4. and so on.

Since you revisit same rooms several times under different circumstances, you need to introduce a condition, that would tell you when you need to start a dialog and when not.

For example, you could create a global variable called "int InCutscene;" (or rather use more descriptive name, since you game may have many cutscenes).
In the first dialog you set it up:
Code (ags) Select

@2
Characterone: blah blah blah
Charactertwo: blah blah
InCutscene = 1; <--- set variable
player.Changeroom(9); <-- that's the "cutscene" room
stop <---- end the dialog


In the room's 9 "After fade-in" event do:
Code (ags) Select

// room 9
function room_AfterFadeIn()
{
    if (InCutscene == 1)
    {
        // play cutscene
        InCutscene = 2; // update variable
        player.Changeroom(4, 400, 400); <-- that's the previous room, the player is supposed to go back to where he was during the first part of the dialogue
    }
}


And in the room's 4 "After fade-in" event you launch the following part of the dialog:

Code (ags) Select

// room 4
function room_AfterFadeIn()
{
    if (InCutscene == 2)
    {
        dDialogPart2.Start(); // launch second part of dialog
    }
    else
    {
        // something else
    }
}


it worked! thank you so much!

an int type variable works just fine, but it needs three values in order for the script to not repeat the second part of the dialogue everytime the character enters the room. a friend of mine suggested a boolean type variable, which makes it even simpler in my case.

room 9:

Code (ags) Select

function room_AfterFadeIn()
{
       Wait(40);
        // play cutscene
        InCutscene = true;
        player.ChangeRoom(4, 484, 400, eDirectionRight);
}


room 4:

Code (ags) Select

function room_AfterFadeIn()
{
    if (InCutscene)
      {
        dDialog4.Start(); // launch second part of dialog
          dDialog1.Start(); // launch second part of dialog
          InCutscene = false;
    }
}


dialog1:

Code (ags) Select

Character: blah blah.
player.ChangeRoom(9);
option-off 2
stop


and of course, the final part of the dialogue goes in a new ddialog. that's it!

thank you so much for your help!
Title: Re: Cutscene (changeroom) in the middle of a dialogue
Post by: Lurch on Wed 14/02/2018 13:44:22
Quote from: Kumpel on Mon 12/02/2018 10:22:29
What about simply changing the room's background frame or putting an object in the size of the screen in front of everything? Wouldn't that suffice too? (Me trying to think practical...)

this one also seems like a smart solution that could've worked in my case. i'll try it out!