Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: aedwards00 on Wed 03/03/2010 00:00:14

Title: Have character on_click functions in a room script file?
Post by: aedwards00 on Wed 03/03/2010 00:00:14
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.
Title: Re: Have character on_click functions in a room script file?
Post by: monkey0506 on Wed 03/03/2010 00:01:56
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... :-\
Title: Re: Have character on_click functions in a room script file?
Post by: aedwards00 on Wed 03/03/2010 00:12:15
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?
Title: Re: Have character on_click functions in a room script file?
Post by: monkey0506 on Wed 03/03/2010 00:17:32
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
Title: Re: Have character on_click functions in a room script file?
Post by: aedwards00 on Wed 03/03/2010 00:21:59
Hehe damn it's like you're psychic, as I was writing my last post I was thinking "I wonder if AGS has switch...".
Title: Re: Have character on_click functions in a room script file?
Post by: CShelton on Wed 03/03/2010 00:43:37
Can't you hack enums to make switch-like behavior?

Monkey in 3..2..1