GUI blocking keys

Started by TDBFW1, Sun 15/10/2017 16:11:37

Previous topic - Next topic

TDBFW1

Thanks a lot for the suggestions. However, in one of my rooms (Not the test room with the code given), it needs to run during room_Rep_exec. This stems from a workaround. As SetRestartPoint() only restarts the game after a non-blocking loop, and my room immediately starts with a blocking script (I.e, a cutscene), I've set up a timer for one loop (To restart the game) and put the rest in room_Rep_exec, something like this:

Code: ags

function room_FirstLoad()
{
SetRestartPoint();
SetTimer(1, 1);
}

function room_RepExec()
{
if (IsTimerExpired(1))
{
int ran=Random(3);
if (ran == 0)
{
  HallRan=true;
  aGrandfather_Clock.Play(eAudioPriorityLow, eRepeat);
  Wait(20);
  cMaid.Say("Looks like I don't have to wind up the grandfather clock.");
  ClockPlaying=true;
  Wait(20);
  blink();
  cMaid.Say("Now which cup did the chef ask for?");
  cMaid.Walk(140, 190, eBlock);
  cMaid.FaceDirection(eDirectionRight, eBlock);
  Wait(40);
  oPinkCup.Visible=false;
  cMaid.Say("That's the one!");
  Wait(20);
  cMaid.Say("Now isn't there another thing the chef asked for?");
  blink();
  oVase.Visible=false;
  Wait(20);
  cMaid.Walk(257, 195, eBlock);
  cMaid.Say("Now I'm ready to go to the chef.");
  if (DifficultyEasy)
  {
    mouse.Mode=eModePointer;
    gNotebook.Visible=true;
  }
}
etc.
Now I don't know where to put the code in my script. Is it better to put it in Globalscript? Is there a better way to restart a room? Or should I just put the code for when the notebook is closed at the end of my room_Rep_exec function?

Sorry for the long post, it's become a bit of a mess.

BTW, you can see where the notebook closed code is meant to slot in, in the DifficultyEasy section.

Khris

If you want to do something after the user closes the notebook in more than one room, you can use CallRoomScript().
In the button handler (I assume) in the global script, where you turn gNotebook back to invisible, add CallRoomScript(1);
Then add this to your room script:
Code: ags
function on_call(int param) {
  if (param == 1) {
    player.Walk(..);
  }
}

TDBFW1

Sorry, I'm new to programming. Could you explain that a little simpler? :P

Khris

I assume you have a button on gNotebook that closes it? In that case you should have something like this in your GlobalScript:

Code: ags
function btnCloseNotebook_OnClick(GUIControl* control, MouseButton button) {
  gNotebook.Visible = false;
}


What you do is add a line to that:

Code: ags
function btnCloseNotebook_OnClick(GUIControl* control, MouseButton button) {
  gNotebook.Visible = false;
  CallRoomScript(1);
}


This line makes AGS call on_call(1); in the current room's script.
Which means you can use this to run commands right after the user closes the Notebook (or some other global event).

You do this by adding the on_call function to your room script. Consider it the room's "user closes notebook" event.

Code: ags
function on_call(int param) {
  if (param == 1) {
     player.Walk(180, 170, eBlock, eAnywhere);
  }
}


The parameter is there in case you want to also use this mechanism for other things. It's like with timers.

TDBFW1

I think I understand. I'm using a key press rather than a button but I assume it will still work.

SMF spam blocked by CleanTalk