Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Vince Twelve on Mon 16/07/2007 07:17:16

Title: Running script only while blocking [solved!]
Post by: Vince Twelve on Mon 16/07/2007 07:17:16
Maybe it's my lack of sleep, but in my head this was easy...

I have a batch of code that I want to run ONLY while the game is in the middle of some blocking function (walking, animating, wait();, etc).  My original plan was to stick this code in the repeatedly_execute_always:

if(mouse.Mode==eModeWait){
  //execute this batch of code
}

But it doesn't do anything when the game is blocking.  So, I change eModeWait to eModeWalkTo, and it works perfectly as long as the cursor mode is walk to, even if the cursor is set to walk to and then a blocking cutcene starts (thus changing the cursor to the wait cursor's graphic), and even when I change back and forth between modes in the middle of a blocking function.  It seems to work with every mode except wait, the one mode I want it to work with...

Does a blocking function not actually change the cursor to the wait mode?  It seems like it only changes the mouse's graphic.

So, my next thought was to run the script based on the cursor's graphic, but there's no mouse.graphic or some such variable (correct me if I'm wrong).

But this may all be pointless if there's a better way to run a block of script only when the game is blocking.  Help?
Title: Re: Running script only while blocking
Post by: Khris on Mon 16/07/2007 07:25:54
Try mouse.GetModeGraphic(mouse.Mode), not sure if it'll work though.
Title: Re: Running script only while blocking
Post by: Vince Twelve on Mon 16/07/2007 07:35:20
It doesn't... it constantly returns the graphic of the mouse mode used before the blocking function started.  Thanks, though!

Any more ideas?
Title: Re: Running script only while blocking
Post by: Khris on Mon 16/07/2007 07:56:58
Here's something that might help:

int repcycles;
int repacycles;

function repeatedly_execute_always() {
  if (repacycles>repcycles) {

    // blocking-only code

    lbl.Text=String.Format("X: %4d", Random(2000));
  }
  repacycles++;
  if (repacycles==32000) {
    repacycles=1;
    repcycles=0;
  }
}

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  repcycles=repacycles;
}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE


Works during a blocked walk and while player is saying dialog lines.
Doesn't work while a Display window or Dialog choice GUI is displayed.
Title: Re: Running script only while blocking
Post by: Vince Twelve on Mon 16/07/2007 08:20:51
I thought about using something like that, but it just seemed so... inelegant for such a simple effect that I'm trying to add in.  But I may end up using this.  Thanks!

I still wonder why the mouse doesn't actually change to the wait mode when blocking, though.
Title: Re: Running script only while blocking
Post by: strazer on Mon 16/07/2007 12:00:53
Quote from: Vince Twelve on Mon 16/07/2007 07:17:16Does a blocking function not actually change the cursor to the wait mode?  It seems like it only changes the mouse's graphic.

Exactly.
Title: Re: Running script only while blocking
Post by: Vince Twelve on Mon 16/07/2007 13:48:10
Ah.  I see.  I guess I can understand why.  Thanks for the confirmation strazer!

For now, Khris' workaround is working around!
Title: Re: Running script only while blocking
Post by: Scorpiorus on Mon 16/07/2007 14:29:58
By the way, there is the IsInterfaceEnabled() (http://www.adventuregamestudio.co.uk/manual/IsInterfaceEnabled.htm) function to help you check for a blocking situation:


function repeatedly_execute_always() {

    if ( ! IsInterfaceEnabled() )
    {
        // your code here
    }

}

Title: Re: Running script only while blocking
Post by: Vince Twelve on Tue 17/07/2007 03:25:00
Beautiful!  That's the elegant solution I was looking for.  I had never seen this function before and hadn't found it because I thought that I could find a blocking state based on the mouse, not the interface.  Thank you Scorp!
Title: Re: Running script only while blocking [solved!]
Post by: Scorpiorus on Tue 17/07/2007 17:09:33
No prob, and yeah it's rather hard to spot that function to have something to do with blocking -- I just happened to code a similar situation back in the old days of pre-object-oriented scripting in AGS, and so I shared.

:)