Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mølck on Fri 19/11/2021 13:55:53

Title: Call a room function from GlobalScript
Post by: Mølck on Fri 19/11/2021 13:55:53
I have read the manual and searched the forums. As I understand it is impossible to call a room function from GlobalScript. However I often need to do exactly that (for instance from character events). I can make workarounds with global variables, continuously listening for a change in these in the room script, but this a bad setup. Is there really no way to directly make room manipulations from a character event or other GlobalScript funcitons? thanks.
Title: Re: Call a room function from GlobalScript
Post by: Khris on Fri 19/11/2021 14:51:27
You can do this with CallRoomScript(int value);.

Add function on_call(int value) { ... }  to your room script to handle the calls.

Also note that you can access current room objects / hotspots from the global script using the object[] and hotspot[] arrays.
Title: Re: Call a room function from GlobalScript
Post by: Crimson Wizard on Fri 19/11/2021 19:43:16
Related article from the manual: https://adventuregamestudio.github.io/ags-manual/Globalfunctions_General.html#callroomscript
Title: Re: Call a room function from GlobalScript
Post by: Mølck on Mon 22/11/2021 11:45:24
Thanks a lot!, I missed that one - it didn't appear in any of my many searches  :grin: . That should do the trick. It still requires some extra maintenance with those int parameters though. Maybe I'll add some global variables to hold these int values.
Title: Re: Call a room function from GlobalScript
Post by: Crimson Wizard on Mon 22/11/2021 12:43:32
Quote from: Mølck on Mon 22/11/2021 11:45:24It still requires some extra maintenance with those int parameters though. Maybe I'll add some global variables to hold these int values.

AGS has few of methods of defining global constants:

1) #define - creates a macro
Code (ags) Select

#define MY_VAR 100

advantage: can be anything, even a line of code
disadvantage: type is guessed from the value, if used incorrectly error messages may be confusing.

2) enum - creates a list of values
Code (ags) Select

enum CallRoomID
{
    eCallRoom_DoThis,
    eCallRoom_DoThat,
    eCallRoom_AnotherThing
};

advantage: groups constants together, can be used as a variable/argument type in your custom functions.
disadvantage: only integer.

3) Regular global variabes, that are initialized once and never changed.
advantage: can be any type;
disadvantage: there's no prevention from changing it.