Do once before fade in (SOLVED)

Started by Nixxon, Wed 22/06/2016 07:07:56

Previous topic - Next topic

Nixxon

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

Nixxon

NEVERMIND, it randomly works now ;)

Khris

For future reference, the screen is faded out during room_Load().
I guess you moved the code to the top of room_afterFadein()?

Nixxon

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.

Khris

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.

Nixxon

#5
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
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.

Khris

#6
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:
Code: ags
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()
{
}

Nixxon

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

SMF spam blocked by CleanTalk