Global scripts disabling hotspots

Started by Glenjamin, Thu 06/08/2015 20:42:21

Previous topic - Next topic

Glenjamin

I'm trying to disable a hotspot when the player gives a character an item. Since the character scripting is in the global script, I can't disable the hotspot from there. How can I do this?

Gurok

You can use the hotspot array. You need to look at the hotspots in your room and find the ID of the hotspot you want to disable, then disable the hotspot at that index. e.g.:

Code: ags
hotspot[1].Enabled = false;
[img]http://7d4iqnx.gif;rWRLUuw.gi

Crimson Wizard

#2
There is also a more complicated, but at the same time more logically correct path, that involves sending a user-defined "event" to room script and have the room script handle it.

I would mention it simply for completeness, because sometimes it can be useful, and also it is more logically strict, because you do not want your global script to access rooms data without knowing exactly what's what, and you do not want to occasionally change hotspot in the different room.
Also sometimes you may have similar event for multitude of rooms.

So, there is this function called "CallRoomScript", that takes only one "value" parameter, which is a user-defined value. For example:
Code: ags

CallRoomScript(1); // 1 here is a magical value, which meaning is known only by you :)

In the room script you may write "on_call" handler (you'll have to do this yourself, it is not mentioned on the Event Handlers list):
Code: ags

function on_call (int value)
{
    if (value == 1)
    {
        hMyHotspot.Enabled = false;
    }
}



It is super useful to not use literal numbers, though, because people tend to forget their meaning fast enought. Instead, you may (should) define constants.
Like this:
Code: ags

// in GlobalScript.ash
// all the custom room events:
//

enum MyRoomEvents
{
    Event_PlayerGetsItem,
    Event_SomethingElseHappened
}

// In GlobalScript.asc, when player gets item --
CallRoomScript(Event_PlayerGetsItem);

// In the room script
function on_call (int value)
{
    if (value == Event_PlayerGetsItem)
    {
        hMyHotspot.Enabled = false;
    }
}

SMF spam blocked by CleanTalk