Cutscene

Started by Vincent, Sun 01/07/2018 13:03:45

Previous topic - Next topic

Vincent

So I was working on a cutscene which is looking something like this:
Code: ags

function room_RepExec()
{
  StartCutscene(eSkipESCOnly);
  lblTesto.Text = "Hello world 1";
  WaitMouseKey(9999);
  
  lblTesto.Text = "Hello world 2";
  WaitMouseKey(9999);

  // some more here

  EndCutscene();
  player.ChangeRoom(2);
}


Anytime I try to skip the cutscene the game freeze. I like how the WaitMouseKey function work because it allow me to block the script til a certain time until a key is pressed. If I remove the start cutscene and handle the change room by checking if isKeyPressed(eKeyEscape) then the player doesn't change room because the key get listened to the WaitMouseKey and it jump to the next line of code instead of changing room. Any advice on how can I do something like this?

Crimson Wizard

#1
To begin with the most important thing, if you look here, one of the first rules for making games with AGS that Snarky loves to repeat is:
Quote
3. If you're putting code in repeatedly_execute, there's probably a better way.

Sometimes it may be said even: "If you're putting code in repeatedly_execute, there's a big chance your are doing it wrong".

This is not because "rep exec" is a useless function, but simply because lots of people are using it for wrong purposes.

room_RepExec is a function that supposed to repeat every game frame (40 times per second by default). Ask yourself: do you really intend to repeat this code over and over again every game frame?
If the answer is negative, then don't put this code in repeatedly_execute.


If this sequence is supposed to occur as soon as the room starts, then logical place for it is in "room after fade-in" event. Is there a reason you did not put it there?

Vincent

Hi Crimson Wizard, the reason is that before putting the code into the function repeatedly execute it was inside the function afterfadein and the behaviour was exactly the same.

Snarky

That is not a good reason.

Crimson Wizard

Quote from: Vincent on Sun 01/07/2018 13:50:40
Hi Crimson Wizard, the reason is that before putting the code into the function repeatedly execute it was inside the function afterfadein and the behaviour was exactly the same.

Hmm, well, that's not a reason to move it to repeatedly execute, that may only make things worse. I strongly recommend to move it back to AfterFadeIn.

So, are you saying that WaitMouseKey does not work in cutscenes? Or maybe it does not update the screen and it looks like game is frozen? I'd like to test this out.

Vincent

The main problem is that by using that code (in afterfadein or repeatedly execute) when I press esc to escape the cutscene the game freeze. It seems like it does not update the screen and it looks freezed as you said. So I was trying to find a way to use WaitMouseKey so to block the script til a key is pressed but without using the start cutscene function. I have try to escape all the pseudo cutscene and to make the player change room by checking if IskeyPressed(eKeyEscape) but when pressing escape instead of changing room it detect a key press for WaitMouseKey and so the change room doesn't get call.


Crimson Wizard

#6
Quote from: Vincent on Sun 01/07/2018 14:15:59
The main problem is that by using that code (in afterfadein or repeatedly execute) when I press esc to escape the cutscene the game freeze.

Oh, you mean it freezes when you press Escape? At first I thought you mean it freezes at WaitForKey.

This is strange, I've just tested exactly same code in a game and it worked either way (by pressing Esc, and clicking through).

EDIT: You have "// some more here" comment, what kind of commands are there?

Vincent

Yes, the game freeze when I press Escape to skip the cutscene and I believe it is because of the WaitMouseKey(9999).
If I remove them then it skip the cutscene just fine.

Code: ags

function room_AfterFadeIn()
{
  StartCutscene(eSkipESCOnly);
  lblTesto.Text = "Hello world 1";
  WaitMouseKey(9999);
  
  lblTesto.Text = "Hello world 2";
  WaitMouseKey(9999);

  gDialog.TweenTransparency(0.5, 100, eEaseLinearTween, eNoBlockTween);
  gScreen.TweenFadeIn(0.6, 0, eEaseLinearTween, eBlockTween);
  gIntro.BackgroundGraphic = 3558;
  gDialog.TweenTransparency(0.5, 0, eEaseLinearTween, eNoBlockTween);
  gScreen.TweenFadeOut(0.6, 100, eEaseLinearTween, eBlockTween);
  
  lblTesto2.Text = "Hello world 3";
  WaitMouseKey(9999);

  lblTesto2.Text = "Hello world 4";
  WaitMouseKey(9999);

  EndCutscene();
  player.ChangeRoom(2);
}


In this case for me would be useful to use WaitMouseKey because it block the script til a key (or mouse click) is pressed. Now I'm trying to avoid (StartCutscene(eSkipESCOnly), EndCutscene) because when I press Esc it freeze the game.

I'm trying a workaround to skip the pseudo cutscene and make the player change room by using IskeyPressed(eKeyEscape) in repeatedly execute. But then IskeyPressed doesn't run because there is WaitMouseKey which is running and detect the key press.

Crimson Wizard

#8
Quote from: Vincent on Sun 01/07/2018 15:23:27
Yes, the game freeze when I press Escape to skip the cutscene and I believe it is because of the WaitMouseKey(9999).

Like I said, I tried your code with WaitMouseKey, and it does not freeze. Of course, it is still hypothetically possible that a combination of WaitMouseKey with something else causes a freeze...

I am more suspicious about tweens. Is there any check for skipped cutscenes inside tween module?

Perhaps, try this and see if that changes anything:
Code: ags

  if (Game.SkippingCutscene)
  {
    gIntro.BackgroundGraphic = 3558;
    // TODO: set dDialog and gScreen to the final looks (immediately)
  }
  else
  {
    gDialog.TweenTransparency(0.5, 100, eEaseLinearTween, eNoBlockTween);
    gScreen.TweenFadeIn(0.6, 0, eEaseLinearTween, eBlockTween);
    gIntro.BackgroundGraphic = 3558;
    gDialog.TweenTransparency(0.5, 0, eEaseLinearTween, eNoBlockTween);
    gScreen.TweenFadeOut(0.6, 100, eEaseLinearTween, eBlockTween);
  }

Vincent

Quote from: Crimson Wizard on Sun 01/07/2018 15:29:18
Like I said, I tried your code with WaitMouseKey, and it does not freeze. Of course, it is still hypothetically possible that a combination of WaitMouseKey with something else causes a freeze...

I am more suspicious about tweens. Is there any check for skipped cutscenes inside tween module?

Perhaps, try this and see if that changes anything:
Code: ags

  if (Game.SkippingCutscene)
  {
    gIntro.BackgroundGraphic = 3558;
    // TODO: set dDialog and gScreen to the final looks (immediately)
  }
  else
  {
    gDialog.TweenTransparency(0.5, 100, eEaseLinearTween, eNoBlockTween);
    gScreen.TweenFadeIn(0.6, 0, eEaseLinearTween, eBlockTween);
    gIntro.BackgroundGraphic = 3558;
    gDialog.TweenTransparency(0.5, 0, eEaseLinearTween, eNoBlockTween);
    gScreen.TweenFadeOut(0.6, 100, eEaseLinearTween, eBlockTween);
  }
I have had a look at the Tween module and it doesn't seems that there is something about a check for the skipped cutscenes. If you say that the WaitMouseKey(9999) it doesn't freeze for you then it is something else. But I have try to simply erase the line regarding the Tween module but the game keep freezed when pressing esc to skip the cutscene. I don't know why.

Vincent

Quote from: Snarky on Sun 01/07/2018 13:59:22
That is not a good reason.

Snarky, so f*****g helpful as usual. :)

Crimson Wizard

#11
We've talked about this with Vincent earlier in PMs, but since this topic thread is public, I thought I should mention that I do regret about making my first reply here look like I was giving a "tutorial". I was probably very absent minded when writing it, and did not realize in time that it looks unrespectful. Besides, it actually was irrelevant in this context.

It's also possible I did this in the past too, in which case I'd like to apologize if I offended anyone else. I can be carried away sometimes.

Vincent

No problem with you Crimson Wizard, I have accepted your excuses.

SMF spam blocked by CleanTalk