Custom Display -function - How to replicate blocking [SOLVED]

Started by WHAM, Wed 15/02/2012 10:32:28

Previous topic - Next topic

WHAM

I'm trying to create a custom GUI that I could use instead of the normal display function inside AGS.
With the normal AGS code, a function reporting information to the player might look something like this:
Code: ags

int whiler = 0;

while (whiler <= 9) {
  Display("The whiler is now %d", whiler);
  whiler++;
}


What this does is DISPLAY the default text "The whiler is now" and the value of the variable, pausing the script execution until the player either presses a key or clicks the mouse to dismiss the displayed text.

What I want to be able to do is:

Code: ags

int whiler = 0;
int msg;

while (whiler <= 9) {
  msg = String.Format("Message content - Whiler is %d", whiler);
  Notify(currentgamespeed, "Header", "msg ", "Dismissal button text");
  whiler++;
}


My current Notify -function looks somewhat like this:

Code: ags

function Notify(int speedatpause, String Header, String Message, String BtnTxt) {
  PauseGame(); 
  Gspeedatpause = speedatpause;
  Time_Currentspeed = 0;
  GUI_Notificatio.Visible = true;
  label_NotHed.Text = Header;
  label_NotMsg.Text = Message;
  btn_NotConfirm.Text = BtnTxt;
}


It seems I was falsely under the impression that the mere act of adding the PauseGame(); to the start of the function and having the dismissal button give the UnPauseGame() -function would be enough, but it seems I was sorely mistaken.

Can anyone explain to me how the built-in Display(); -function pauses the running of a script and how I could replicate it in my custom function?

Edit: clarification: the manual clearly states that Display() is a blocking function. It is this blocking property that I seek to replicate in my function, with the clicking of the button inside the GUI acting as a trigger to undo the blocking, just like in the Display() -function.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

WHAM

I found this thread: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=45094.0

With this code:
Quote from: Khris on Fri 06/01/2012 06:05:53
Try this:

Code: ags
// top of GlobalScript.asc
void noloopcheck HaltGame(int k) {
  while (!IsKeyPressed(k)) {
    Wait(1);
  }
}


Then:
Code: ags
  gElevator.Visible = true;

  HaltGame(eKeySpace);
    
  Display("Should not see this until after space was pressed");


As I need to show multiple consecutive notifications using this script, I modified it as follows:
Code: ags

void noloopcheck HaltGame(int k) {
  while (!IsKeyPressed(k)) {
    Wait(1);
  }
  GUI_Notificatio.Visible = false;
  Wait(5);
}


Adding the extra wait command in the end stops the single press of the space bar from triggering all the notifications at once.


Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

monkey0506

I think what would make more sense than adding an additional lag to your function would be to just change how often you're polling (checking) the keys:

Code: ags
import void HaltGame(int k, int delay=5);

void noloopcheck HaltGame(int k, int delay)
{
  while (!IsKeyPressed(k))
  {
    Wait(delay);
  }
}


It's up to you though, whatever works for your game! ;)

SMF spam blocked by CleanTalk