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
Help with script for "3 levers to unlock a door"
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#3
RE: Help with script for "3 levers to unlock a door"

Hey hey, looks like a script guru in the making. You've got the right idea here, but you'll want to compress this script. Try something like this

PHP Code: (Select All)
void OnStart()
{
    
//here we'll add the lever callbacks
    
for(int i=1;i<=3;i++) SetEntityConnectionStateChange("lever"+i"LeverPull");
}

void LeverPull(string &in leverNameint leverState)
{
    
// if lever is at correct state, set it stuck and add 1 to lever var
    
if(leverState == 1
    {
        
AddLocalVarInt("leverStates"1);
        
SetLeverStuckState(leverName1true);
    }
    
// solve the puzzle if all states are 1
    
if(GetLocalVarInt("leverStates") == 3func01();
}

void func01()
{
    
//puzzle solved! hoorah!
    
SetSwingDoorLocked("prison_cellardoor"falsetrue);
    
PlaySoundAtEntity("""unlock_door""prison_cellardoor"0false);
    
GiveSanityBoostSmall();


This is a cleaner way to do the code. Instead of having a separate function for each lever pulled, I combined them into one. There's no real need to track exactly which lever was pulled, so the script becomes even shorter, since the what we're focusing on is the lever changing states, not on which lever changes states.

Things I changed:
Compressed the call stack which adds the connection state callbacks.
Compressed the lever pull functions into a single function. Also changed the name to "LeverPull".
The local variable name.

Hope it works for ya. I had to put down my apple to write this....now I'm gonna pick it up and devour the rest of it.

(This post was last modified: 01-29-2012, 05:21 PM by palistov.)
01-29-2012, 05:18 PM
Find


Messages In This Thread
RE: Help with script for "3 levers to unlock a door" - by palistov - 01-29-2012, 05:18 PM



Users browsing this thread: 1 Guest(s)