When to use run-script in dialog.

Started by quixotecoyote, Sat 18/03/2006 03:29:00

Previous topic - Next topic

quixotecoyote

What I've been doing so far is when I need a cutscence or action performed based on a dialog choice, I use run-script in the dialog  and write the necessary scripting in the global script. 

My question is, my global script is getting awful cluttered.  Is there a better way to do this so that my one shot room-specific actions don't have to go through the global script?   Or at least an easy way to redirect the script so the code goes on the room script?

RickJ

CallRoomScript() is your friend.  :D  Check it out in the manual, it's pretty self-explanatory.

Code: ags

CallRoomScript (int value)

Calls the on_call function in the current room script. This is useful for things like the text parser, where you want to check for general game sentences, and then ask the current room if the sentence was relevant to it.
The on_call function will be called in the current room script, with its value parameter having the value you pass here. This allows it to distinguish between different tasks, and saves you having to use a GlobalInt to tell it what to do.

If the current room has no on_call function, nothing will happen. No error will occur.

You write the on_call function into the room script ("Edit script" button on Room Settings pane), similar to the way you do dialog_request in the global script: 

function on_call (int value) {
  if (value == 1) {
    // Check text input
    if (Parser.Said("get apple"))
      Display("No, leave the tree alone.");
  }
}


quixotecoyote

Thanks, I doubt I would have found that myself.   I wonder about the implications of this:

QuoteThe function doesn't get called immediately; instead, the engine will run it in due course, probably during the next game loop, so you can't use any values set by it immediately.

could I counter this by adding  wait(1) after CallRoomScript()?

SMF spam blocked by CleanTalk