Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Nixxon on Wed 22/06/2016 07:07:56

Title: Do once before fade in (SOLVED)
Post by: Nixxon on Wed 22/06/2016 07:07:56
Hey all,

Trying to display a graphic the first time a player enters a room (before fade in). The first time player enters room function displays 'after' the fade-in. I've tried the below code to no avail :(

Code (ags) Select
function room_Load()
{
    if (Game.DoOnceOnly("Some More Time Later")) {
ginvwindow.Visible = false;
gIconbar.Visible = false;
  Overlay* myOverlay = Overlay.CreateGraphical(0, 0, 25, true);
Wait(120);
    }
mouse.Mode = eModeWalkto;
}
Title: Re: Do once before fade in
Post by: Nixxon on Wed 22/06/2016 07:12:30
NEVERMIND, it randomly works now ;)
Title: Re: Do once before fade in (SOLVED)
Post by: Khris on Wed 22/06/2016 09:03:12
For future reference, the screen is faded out during room_Load().
I guess you moved the code to the top of room_afterFadein()?
Title: Re: Do once before fade in (SOLVED)
Post by: Nixxon on Wed 22/06/2016 11:30:14
Nah, I wanted to run the code (before) the room faded in AND the first time the player enters the room.

The 'First time player enters room' Function seems to pertain to (after fade in) only.

Therefore I had to use the DoOnceOnly.
Title: Re: Do once before fade in (SOLVED)
Post by: Khris on Wed 22/06/2016 15:22:13
I'm completely aware of what you wanted to do, but you wouldn't want to display an overlay, then wait 120 frames before the room has faded in. Because, well, the screen is still black.
The solution, afaik, is to move the code to the top of afterFadein and use Game.DoOnceOnly(), because that, in essence, creates a "first time player enters screen" event that runs before the remaining afterFadein code, not after like the built-in one.

This is a common question and other people might find this thread via the search, that's why it's a good thing to post the solution and not just write a cryptic one-liner.
Title: Re: Do once before fade in (SOLVED)
Post by: Nixxon on Thu 23/06/2016 00:21:20
Makes sense Khris, I will keep that in mind. :) *note that i was completely unaware why it wasn't working initially*

The ultimate goal in this instance was/is to display a "Some time later..." full screen graphic, the first time (first time only), the player enters a particular room.

When I used the code in the "first time player enters room function", the room would fade in, THEN the graphic would appear.

In using the below code in the "load before fade in function" I was able to achieve this.

Code (ags) Select
function room_Load()
{
    if (Game.DoOnceOnly("Some More Time Later")) {
ginvwindow.Visible = false;
gIconbar.Visible = false;
  Overlay* myOverlay = Overlay.CreateGraphical(0, 0, 25, true);
Wait(120);
    }
mouse.Mode = eModeWalkto;
}


Hope that clarifies somewhat.
Title: Re: Do once before fade in (SOLVED)
Post by: Khris on Thu 23/06/2016 08:22:49
I'm sorry to drag this out, but now you've posted the code that you initially said didn't work as solution to your problem.

I did a quick test and found out that "first time enters room" is executed before "after fadein".
Anyway, the solution is to hide the GUIs and create the overlay in room_Load, so the room will fade in already showing the desired elements, then Wait(120) in room_FirstLoad.

Full script, with the relevant functions in order of execution:
Overlay *someTimeLater;

function room_Load()
{
  if (Game.DoOnceOnly("some time later")) {
    ginvwindow.Visible = false;
    gIconbar.Visible = false;
    someTimeLater = Overlay.CreateGraphical(0, 0, 25, true);
  }
}

/* screen is faded in */

function room_FirstLoad()
{
  Wait(120);
  someTimeLater.Remove();
}

function room_AfterFadeIn()
{
}
Title: Re: Do once before fade in (SOLVED)
Post by: Nixxon on Thu 23/06/2016 22:31:36
Thanks Khris,

I guess it doesn't matter if it runs every time since it's 'before' the fade-in.

EDIT - The code worked all along, as per my second post