Accesing hotspot from outside room script

Started by janro, Thu 05/02/2015 11:47:35

Previous topic - Next topic

janro

Hi everybody.

We are building a script for managing dialogs for all interactions in game.
Idea is to get access from a single script file to all objects, items and hotspots and store their values into structs. I'm implementing the hotspots part and have a problem accessing them from that script file.

I'm accesing to hotspot with it's ID like this:
Code: ags

hSpotDialogs[1].name = hotspot[1].Name;

hSpotDialogs is a struct where all data from hotspots should be stored.

I've read that hotspots can be accessed from a global script with it's ID but I don't know is it possible to access them from a local script with same manner?

When I run the game I get error "Null string supplied to CheckForTranslations". I'm not sure is that error caused because hotspot[1].Name is null at the moment script is executed at start_game function in global script. Or doesn't script get the value out from hotspot[1].Name because script is not global nor is located in room script?

When I import the script into room script and execute it when room is entered first time, values from hotspot is stored fine into struct. But we prefer to keep dialog script local and execute them from game_start if it's possible.

Would someone please clear me out with this? I'm happy to deliver more details if necessary. :)

Crimson Wizard

Quote from: janro on Thu 05/02/2015 11:47:35
I've read that hotspots can be accessed from a global script with it's ID but I don't know is it possible to access them from a local script with same manner?
What do you call "local script"? Custom script modules are not local, they are global as well as GlobalScript. Room scripts may be called "local", perhaps, in the sense that they are only accessible while running particular room.
Regardless, hotspots may be accessed from any script, because current Room is a global object, so are its contents.

Quote from: janro on Thu 05/02/2015 11:47:35
When I import the script into room script and execute it when room is entered first time, values from hotspot is stored fine into struct. But we prefer to keep dialog script local and execute them from game_start if it's possible.
You can't get any information about hotspots at "game_start", because hotspots are part of particular room, and game_start is run before first room is loaded.
You would probably need to assign your hotspot names at room loading event. Since you need to do so at every room, it would be better to use generic "on_event" function (in GlobalScript or any custom modules):

Code: ags

function on_event(EventType event, int data)
{
    if (event == eEventEnterRoomBeforeFadein)
    {
        // init array of hotspot names here
    }
}


janro

Thanks for your quick reply!

By "local script" I meant that custom script. I'm still very new with AGS and still learning the right terms.

I'll give a try what you suggested, thanks again! :)

SMF spam blocked by CleanTalk