Frictional Games Forum (read-only)

Full Version: Global Var Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys! I've got a problem with global vars. I have a map where you have to activate a lever, then the global var ("VarEle") should switch to 1 (activate an elevator). The script of the map (where the lever is):


void OnEnter()
{
SetEntityConnectionStateChangeCallback("lever1", "func_piston");
}


void func_piston(string &in asEntity, int alState)
{
if (alState == 1)
{
AddGlobalVarInt("VarEle", 1);
SetMoveObjectStateExt("Entity_Piston", 0.6, 0.6, 8, 0, false);
PlaySoundAtEntity("", "move_gate.snt", "Entity_Piston", 0, false);
return;
}
}

So, the var should effect an elevator to switch the map (fade out and change map). The script of the other map (where the elevator is):

void OnEnter()

{
CreateParticleSystemAtEntity("FountainPourBlood", "ps_childsnake_blood_stream.ps", "ScriptArea_1", true);
CreateParticleSystemAtEntity("FountainPourBlood", "ps_childsnake_blood_stream.ps", "ScriptArea_2", true);
PlayMusic("02_amb_safe.ogg", true, 5.0f, 0.7f, 10, true);
if (GetGlobalVarInt("VarEle")== 1)
{
SetEntityConnectionStateChangeCallback("elevator_lever_2", "activate_attic");
}
}

void activate_attic(string &in asEntity, int alState)
{
if (alState == 1)
{
FadeOut(3);
ChangeMap("attic.map", "PlayerStartArea_1", "", "");
}
}

void OnLeave()
{
StopMusic(0,0);
}

The main problem is that if I pull the lever down, nothing happens. Please correct me, if you know a way to solve this problem Wink
what is the return; for? I don't see any need of it.
So, you mean by nothing happens, even no sound plays?
Edit: I think you should go for this:
Use SetGlobalVarInt instead of AddGlobalVarInt.
Also, Set the variable to 0 in OnStart() at the first map first.