Call a room function from GlobalScript

Started by Mølck, Fri 19/11/2021 13:55:53

Previous topic - Next topic

Mølck

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.

Khris

#1
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.


Mølck

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.

Crimson Wizard

#4
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

#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

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.

SMF spam blocked by CleanTalk