Frictional Games Forum (read-only)

Full Version: Global Varint With Lever
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Forum.
I'm very confused using the Global Varint script. I'm making a script where the player interacts with a lever that unlock something at another map. I spent an hour how to use this script and still have no idea how to use the script. Help ?
In the first map, you'll want a line in OnStart like ...
Code:
SetGlobalVarInt("OtherMapDoorUnlocked", 0);

Then, when the player uses the lever to unlock, you'll want
Code:
SetGlobalVarInt("OtherMapDoorUnlocked", 1);
(assuming 0 is locked and 1 is unlocked)

Now when the player goes over to the other map, in OnEnter, you have a line like

Code:
if (GetGlobalVarInt("OtherMapDoorUnlocked")==1) // if the door has been unlocked
{
      SetSwingDoorLocked("DoorName", false, true);
}

Change names where appropriate
Of course:

It should be like this:

Map with lever
Code:
void OnStart()
{
SetEntityConnectionChangeStateCallback("Lever", "Func");
}

void Func (string &in asEntity, int alState)
{
if (alState == 1)
{
AddGlobalVarInt("Var", 1);
//You may put some sounds if you wish
}
}

Map where the lever takes effect:

Code:
void OnEnter()
{
if (GetGlobalVarInt("Var" == 1))
{
//Unlock your thing
}
}

EDIT: Ninja'd by Adrianis. Although I explain myself better.
Important, this only works if you play the game like you would normally, that is you play the level with the lever, then continue to the other level using a level door or changemap script. If you use the debug menu to directly load a new level, then that is like starting a new game. Meaning if you play the lever level, pull the lever and have the variable set, then use debug menu to load the next level to test if the variable has the correct value it will always fail.
Thanks for the reply guys. I'll try this later when I finished making the map.