Make object visible which is in different room after an action in different room

Started by Raifserdar, Thu 14/03/2019 13:22:44

Previous topic - Next topic

Raifserdar

Hello everyone,
I'm new on AGS and still learning. I need your help on the following.
I have a map. The bookmark on this map is an object ( All bookmarks are object ) and this object is invisible at the beginning of the game.
The object must be visible when the player has found the address of the appropriate location from the computer.
However, the computer is in room 2, the object will be visible after the action.
So the caracter has to make action in room 2, the object which is in Room 10 should be visible as a result of this action.
if (player.Room == 10) object [4] .Visible = True does not work because the object is not in the same room.
I also tried changeroom option but it didn't work too.
I'm trying to make the object visible by typing the code from the global Script. I know I need to use an object number here.
Is there anyone who can help with proper code?
I did a lot of research in the forums but no code didn't work.
I hope I was able to explain the problem clearly.
Thanks.

Crimson Wizard

You cannot do this directly because AGS has only 1 room loaded into memory at one time.
Changing something in another room usually done by saving object's state in a global variable and then applying it to real object from variable on room load (in "Room before fade-in" event)

Crimson Wizard

In your case, where you have a set of locations for a map you may also create an array of booleans and access functions for convenience.

For example:
in GlobalScript.ash
Code: ags

#define MAX_LOCATIONS 10
enum MapLocationType
{
    eLocationStreet,
    eLocationShop,
    eLocationCircus
    // and so on
}

// This function enables/disables locations
import void ToggleMapLocation(MapLocationType index, bool on);
// This function tells if location is enabled or not
import bool IsMapLocationOn(MapLocationType index);


in GlobalScript.asc
Code: ags

bool IsMapLocationOn[MAX_LOCATIONS];

void ToggleMapLocation(MapLocationType index, bool on)
{
    IsMapLocationOn[index] = on;
    // other actions maybe
}

bool IsMapLocationOn(MapLocationType index)
{
    return IsMapLocationOn[index];
}



And then use it in rooms like:
Code: ags

ToggleMapLocation(eLocationCircus, true); // display Circus on map
ToggleMapLocation(eLocationStreet, false); // hide Street location




Then, in the Map room, in "before fade-in" event, you do this:
Code: ags

function Room_Load()
{
    oStreetBookmark.Visible = IsMapLocationOn(eLocationStreet);
    oShopBookmark.Visible = IsMapLocationOn(eLocationShop);
    // and so on
}

Raifserdar

Thank you Crimson Wizard for your quick reply.
I'll try your what you suggest. Hope solve the issue. If not have to make something else from the beginning.

SMF spam blocked by CleanTalk