Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Levers in different levels
LankySpankey103 Offline
Junior Member

Posts: 10
Threads: 3
Joined: Feb 2013
Reputation: 0
#1
Levers in different levels

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 :-)
09-17-2013, 10:43 PM
Website Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#2
RE: Levers in different levels

You can store the lever state in a global variable. E.g.
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.
09-17-2013, 11:39 PM
Find
LankySpankey103 Offline
Junior Member

Posts: 10
Threads: 3
Joined: Feb 2013
Reputation: 0
#3
RE: Levers in different levels

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?
09-18-2013, 11:13 AM
Website Find
LankySpankey103 Offline
Junior Member

Posts: 10
Threads: 3
Joined: Feb 2013
Reputation: 0
#4
RE: Levers in different levels

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.
09-18-2013, 08:07 PM
Website Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#5
RE: Levers in different levels

(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:
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:
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
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);
  }
}
(This post was last modified: 09-18-2013, 11:02 PM by Apjjm.)
09-18-2013, 11:02 PM
Find
LankySpankey103 Offline
Junior Member

Posts: 10
Threads: 3
Joined: Feb 2013
Reputation: 0
#6
RE: Levers in different levels

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!
09-19-2013, 06:37 PM
Website Find




Users browsing this thread: 1 Guest(s)