How can I call room-specific functions with GUIs?

Started by antipus, Sat 10/07/2010 20:39:12

Previous topic - Next topic

antipus

As part of my game, you must open a sweet locking mechanism, which includes a number of animations.  To the side of the mechanism, I'm trying to put a GUI with such helpful buttons as "TIPS," "DIFFICULTY," "RESET," and "EXIT."  The problem is that all GUI functions are automatically defined in the global script, and I want this GUI to affect things specific to the room, like animations, room-specific functions (ie "reset_Lock()"), and the character changing rooms.

I've tried defining the GUI in the room script (AGS failed to find the commands).

I've tried calling room functions in the global script (AGS failed to find the functions).

More creatively, I've tried setting up a global variable (LockGUIClicked), which gets changed by the GUI in the global script. Back in the room, I've got a repeatedly_execute_always() function that calls up room functions whenever that variable is changed.  But any room functions it calls crash the game because they contain animations (reset_Lock()) and other blocking commands (ChangeRoom), which repeatedly_execute_always doesn't like.

The only other option I can think of is making a bunch of objects in the room that LOOK like a GUI, with hotspots underneath that change the objects' images (like my GUI's PushedImage and MouseoverImage) as the mouse moves over.  But that would still probably not act the same.

Any suggestions?
Playing Arden's Vale has been shown to improve morale, revive unconscious kittens, and reverse hair loss.

Wyz

You can use import and export to make functions or variables visible to other scripts.

In the script you have defined the function or variable use export.
In the header file of the script where you defined the function or variable use import.

This could look something like this:

in GlobalScript.asc
Code: ags

int MyInteger;

function MyFunction(int a, int b)
{
    // does stuff
}

export MyInteger, MyFunction;


in GlobalScript.ash
Code: ags

import int MyInteger;
import function MyFunction(int a, int b);
Life is like an adventure without the pixel hunts.

Khris

There's also CallRoomScript which will call on_call in the current room script.

antipus

Thank you both.  The Import/Export trick doesn't work well in this case, seeing as there are a bunch of GUI buttons to import, and likewise a stinking lot of functions in the room I'd have to import to get all of the functionality I'd wanted.

The CallRoomScript did the trick, though.  I used the same numbers I'd set for the global variable, but now that it's not locked in a repeatedly_execute_always function, I can use all of my local room functions that block without AGS getting mad at me.
Playing Arden's Vale has been shown to improve morale, revive unconscious kittens, and reverse hair loss.

SMF spam blocked by CleanTalk