Adventure Game Studio | Forums

AGS Support => Modules, Plugins & Tools => Topic started by: timid_dolphin on Sat 11/06/2022 02:43:52

Title: TOOL: SCABS, tool & technique for scripting non-blocking NPC behaviour and more
Post by: timid_dolphin on Sat 11/06/2022 02:43:52
Hi all,

I've been developing a system for scripting non-player behaviour in AGS inspired by the way the Sierra Creative Interpreter does this.
I present to you: Switch Case Action/Behaviour System, or SCABS for short.

First, characters must have a custom property (int) SCABS which is initialised as zero.

They also have a custom property (int) delayClicker also initialised at Zero.

The SCABS function is a character extender function which returns the character's SCABS value, but can also be used to increment or change this number. (Character.SCABS(1) will increment, Character(50) sets SCABS to 50, Character.SCABS() will just return the SCABS value.)

There's another (character) custom extender function which creates a delay without using a timer, using another custom property 'delayClicker' to count game cycles without having to set a timer. It returns true when it reaches the amount of seconds you call the function with.

Also there's Character.SCABSwalk, which just moves the character to a destination and changes the SCAB value when they get there. Default value is 1, or increment, but can be set to change to any block in the switch case.

But you can use any conditions you want to check and issue the next instruction, just be aware that the switch case is running every game loop so you usually need to change the SCABS value immediately as you issue instructions.

eg Character.delay(2.5) will return true after 2.5 seconds.

USAGE:


In a room script make a function which will be called from room_RepExec() with a switch case like this:
Code (ags) Select

function moveChar(Character* theChar) //can be used for multiple characters
{
  switch(theChar.SCABS())
  {
    case 0: //will initially listen to conditions in this block
      if(theChar.Room == player.Room) //when the character enters this room
      {
        theChar.SCABS(1); // increments SCABS value, and listens to next block
      }
    break;
    case 1:
      //this function listens for two conditions,
      //if the character hasn't reached the destination, and they're not
      //moving, give character instructions to go there.
      //if the character has reached the destination, increment SCABS
      theChar.SCABSwalk(10, 10);
    break;
    case 2:
      if(theChar.delay(4.0)) //after 4 seconds, run this block
      {
        theChar.SCABS(1);
      }
    break;
    case 3:
      theChar.SCABSwalk(10, 20);
    break;
    case 4:
    //this block branches to two different cases, for example
    //if you're using SCABS for a stealth puzzle, checking if the npc
    //can 'see' the player.
    //you can check basically any conditions you want in these.
      if(player.x < theChar.x)//checks if player is to the left of theChar
      {
        theChar.SCABS(20);
      } else {
        theChar.SCABS(40);
      }
    break;
  }
}


Github:
https://github.com/sean-molloy/scabs (https://github.com/sean-molloy/scabs)


Title: Re: SCABS, tool & technique for scripting non-blocking NPC behaviour and more
Post by: newwaveburritos on Sat 11/06/2022 03:54:06
This looks useful!  Thanks for posting.
Title: Re: SCABS, tool & technique for scripting non-blocking NPC behaviour and more
Post by: timid_dolphin on Sat 11/06/2022 06:19:39
Thanks!

Note that you could also use the delay timer to make something happen regularly, like theChar.delay(10.0) will return true every ten seconds, or you could put a randomizing value in there to make something happen at odd frequencies if you wanted.

So you could have a simple function running from the room's repeatedly execute like:

Code (ags) Select


float timing = 3.0;
function oldJoeScratching()
{
  if(cOldJoe.delay(timing))
  {
    runScratchAnimation();  //the thing you wanted to happen
    timing = IntToFloat(4 + Random(8));  // changes timing to random number between 4 and 12
  }
}