Have character on_click functions in a room script file?

Started by aedwards00, Wed 03/03/2010 00:00:14

Previous topic - Next topic

aedwards00

Just a quick question: Is it possible to have the character on_click functions in the room script file(s) in which that character appears?
This would allow me to use the same character in different rooms with different dialogs, without having to test which room they're actually in at the time.
I tried just moving the function into the room script file and it compiles fine, but nothing actually happens when I click the character. Is there a way to tell AGS to look in a specific place for the function? Something i can add in the properties window maybe?

Thanks in advance.

monkey0506

Character, GUI, GUIControl, and InventoryItem interaction event handler functions (such as the OnClick functions) must appear in the global script (GlobalScript.asc) or they will never be called... :-\

aedwards00

Bah :( Oh well thanks for the quick answer anyway.

How do most people deal with re-using characters in multiple rooms? Just have a load of if statements in functions to determine where they are at the time?

monkey0506

Code: ags
function cEgo_Interact() {
  if (player.Room == 1) {
  }
  else if (player.Room == 2) {
  }
  else if (player.Room == 3) {
  }
  else { // any other room number
  }
}


If you specifically need a different interaction for every room you'll need to do something like that. Unless you need a specific interaction for that room though you can just put a generic interaction in the else clause.

BTW, from your other posts you seem to come from a programming background already, so before you ask, no AGS does not have a switch statement. :P

aedwards00

Hehe damn it's like you're psychic, as I was writing my last post I was thinking "I wonder if AGS has switch...".

CShelton

Can't you hack enums to make switch-like behavior?

Monkey in 3..2..1

SMF spam blocked by CleanTalk