Frictional Games Forum (read-only)
Levers in different levels - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Levers in different levels (/thread-23241.html)



Levers in different levels - LankySpankey103 - 09-17-2013

Hey guys!

Sorry if this has been asked before but me and a friend is working on a CS where we want the player to activate 2 levers (one in each level of our CS) and were wondering if this is possible, and how exactly? Is it something with global variables working across different levels of some sort?

Thanks in advance :-)


RE: Levers in different levels - Apjjm - 09-17-2013

You can store the lever state in a global variable. E.g.
Code:
void OnLeave() {
  SetGlobalVarInt("Lever_Map1_state",GetLeverState("MyLever"));
}
You can also set the global variable in the levers state change callback (this way is probably better). Make sure you have the "full game save" property checked for the levers so the state isn't forgotten if you revisit the level.

You can then test the state value (1/-1 depending on "on"/"off") as needed for each lever.


RE: Levers in different levels - LankySpankey103 - 09-18-2013

Thank you, will try that when I get home :-) I have one more question though: How come when you hover the mouse over the "full game save" property, it says that I should use as few of them as possible?


RE: Levers in different levels - LankySpankey103 - 09-18-2013

Okay so i tried your method but no luck. Would you care to take a look at my coding?

So I have in my first room where the locked door is, which the 2 levers are supposed unlock.
Quote:void OnStart()
{
//Variables
SetGlobalVarInt("door_exit", 0);
}

void OnEnter()
{
if(GetGlobalVarInt("door_exit") == 2)
{
SetLevelDoorLocked("level_wood_double_1", false);
}
}

Then in the second room with the first lever i have this:
Quote:void OnStart()
{
SetEntityConnectionStateChangeCallback("lever_grave", "lever_exit_1");
}

void lever_exit_1(string &in asEntity, int alState)
{
if (alState == 1)
{
AddGlobalVarInt("door_exit", 1);
SetLeverStuckState("lever_grave", 1, true);
}
}

And the third room:
Quote:void OnStart()
{
SetEntityConnectionStateChangeCallback("lever_torture", "lever_exit_2");

}

void lever_exit_2(string &in asEntity, int alState)
{
if (alState == 1)
{
AddGlobalVarInt("door_exit", 1);
SetLeverStuckState("lever_torture", 1, true);
}
}

Thanks in advance.


RE: Levers in different levels - Apjjm - 09-18-2013

(09-18-2013, 11:13 AM)LankySpankey103 Wrote: How come when you hover the mouse over the "full game save" property, it says that I should use as few of them as possible?
Every entity you enable full game save on is in the save file forever - so if you did this for loads of entities each map the save file will grow pretty big. It's fine to use for a select few props which you need to remember the state of between maps.

Regarding your code, it looks like it should work provided you visit map 1 first and are pulling the levers in the right direction. Changing the code to the following will allow us to test where stuff is going wrong.

First map:
Code:
void OnStart()
{
  /*GetGlobalVarInt('<stuff>') returns 0 if SetGlobalVarInt hasn't been called yet, so we don't need to init this to 0*/
}

void OnEnter()
{

  //Print some debug messages so we can see the lever states
  AddDebugMessage("Map1 OnEnter()",false);
  AddDebugMessage("lever_grave state: " + GetGlobalVarInt("lever_grave_pulled"),false);
  AddDebugMessage("lever_torture state: " + GetGlobalVarInt("lever_torture_pulled"),false);

  //Unlock the level door if both levers have been pulled
  if(GetGlobalVarInt("lever_grave_pulled") + GetGlobalVarInt("lever_torture_pulled") == 2)
  {
    AddDebugMessage("Opening level door!",false);
    SetLevelDoorLocked("level_wood_double_1", false);
  }
}

Second map:
Code:
void OnStart()
{
SetEntityConnectionStateChangeCallback("lever_grave", "lever_exit_1");    
}

void lever_exit_1(string &in asEntity, int alState)
{
  //This helps us know if this event has triggered
  AddDebugMessage(asEntity + " is in state: " + alState,false);
  
  if (alState == 1)
  {  
     SetGlobalVarInt("lever_grave_pulled", 1);
     SetLeverStuckState("lever_grave", 1, true);
  }
}

Third Map
Code:
void OnStart()
{    
SetEntityConnectionStateChangeCallback("lever_torture", "lever_exit_2");
}

void lever_exit_2(string &in asEntity, int alState)
{
  //This helps us know if this event has triggered
  AddDebugMessage(asEntity + " is in state: " + alState,false);
  
  if (alState == 1)
  {  
     SetGlobalVarInt("lever_torture_pulled", 1);
     SetLeverStuckState("lever_torture", 1, true);
  }
}



RE: Levers in different levels - LankySpankey103 - 09-19-2013

Aha! Found the solution :-) Apparently whenever you "Reload Map" from the debug menu, it doesn't count as OnEnter(). I wasn't aware of that. Thanks a lot Apjjm!