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


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lever-Pulling Combination Help
Kyle Offline
Posting Freak

Posts: 911
Threads: 36
Joined: Sep 2010
Reputation: 7
#1
Lever-Pulling Combination Help

I have been working on a script for a while and for some reason, it doesn't work the way I want it to work. The player is supposed to pull down 5 levers in a certain order and there are 2 combinations that they can use.

These are the levers: 1 2 3 4 5
Combinations: 4 5 2 1 3
5 1 3 2 4

I don't want the combinations to combine in a way. So this is my somewhat advanced script that should have taken care of it, but doesn't work, yet still can run:

void OnStart()
{
    SetLocalVarInt("Lever", 1);
    SetEntityConnectionStateChangeCallback("lever_simple01_22", "L1");
    SetEntityConnectionStateChangeCallback("lever_simple01_23", "L2");
    SetEntityConnectionStateChangeCallback("lever_simple01_24", "L3");
    SetEntityConnectionStateChangeCallback("lever_simple01_25", "L4");
    SetEntityConnectionStateChangeCallback("lever_simple01_26", "L5");
    Check();
}
void Check()
{
    if (GetLocalVarInt("Lever") == 6)
    {
        GiveSanityBoost();
        int x = RandInt(1, 2);
        if (x == 1)
        {
            SetSwingDoorLocked("castle_1", false, true);
            SetSwingDoorClosed("castle_1", false, true);
            return;
        }
        else if (x == 2)
        {
            SetSwingDoorLocked("castle_2", false, true);
            SetSwingDoorClosed("castle_2", false, true);
            return;
        }
    }
}
void L5(string &in asEntity, int alState)
{
    if (alState == 1)
    {
        if (GetLocalVarInt("Lever") == 4)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_26", true);
            return;
        }
        else if (GetLocalVarInt("Lever") == 3)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_26", true);
            return;
        }
        else if ((GetLocalVarInt("Lever") != 3) || (GetLocalVarInt("Lever") != 4))
        {
            SetLocalVarInt("Lever", 1);
            for (int i = 22; i <= 26 && i >= 22; i++)
            {
                SetEntityInteractionDisabled("lever_simple01_"+i, false);
            }
            return;
        }
    }
}
void L4(string &in asEntity, int alState)
{
    if (alState == 1)
    {
        if (GetLocalVarInt("Lever") == 1)
        {
            AddLocalVarInt("lever", 1);
            SetEntityInteractionDisabled("lever_simple_25", true);
            return;
        }
        else if (GetLocalVarInt("Lever") == 2)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_25", true);
            return;
        }
        else if ((GetLocalVarInt("Lever") != 1) || (GetLocalVarInt("Lever") != 2))
        {
            SetLocalVarInt("Lever", 1);
            for (int i = 22; i <= 26 && i >= 22; i++)
            {
                SetEntityInteractionDisabled("lever_simple01_"+i, false);
            }
            return;
        }
    }
}
void L3(string &in asEntity, int alState)
{
    if (alState == 1)
    {
        if (GetLocalVarInt("Lever") == 3)
        {
            AddLocalVarInt("lever", 1);
            SetEntityInteractionDisabled("lever_simple_24", true);
            return;
        }
        else if (GetLocalVarInt("Lever") == 2)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_24", true);
            return;
        }
        else if ((GetLocalVarInt("Lever") != 3) || (GetLocalVarInt("Lever") != 2))
        {
            SetLocalVarInt("Lever", 1);
            for (int i = 22; i <= 26 && i >= 22; i++)
            {
                SetEntityInteractionDisabled("lever_simple01_"+i, false);
            }
            return;
        }
    }
}
void L2(string &in asEntity, int alState)
{
    if (alState == 1)
    {
        if (GetLocalVarInt("Lever") == 1)
        {
            AddLocalVarInt("lever", 1);
            SetEntityInteractionDisabled("lever_simple_23", true);
            return;
        }
        else if (GetLocalVarInt("Lever") == 5)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_23", true);
            return;
        }
        else if ((GetLocalVarInt("Lever") != 1) || (GetLocalVarInt("Lever") != 5))
        {
            SetLocalVarInt("Lever", 1);
            for (int i = 22; i <= 26 && i >= 22; i++)
            {
                SetEntityInteractionDisabled("lever_simple01_"+i, false);
            }
            return;
        }
    }
}
void L1(string &in asEntity, int alState)
{
    if (alState == 1)
    {
        if (GetLocalVarInt("Lever") == 5)
        {
            AddLocalVarInt("lever", 1);
            SetEntityInteractionDisabled("lever_simple_22", true);
            return;
        }
        else if (GetLocalVarInt("Lever") == 4)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_22", true);
            return;
        }
        else if ((GetLocalVarInt("Lever") != 5) || (GetLocalVarInt("Lever") != 4))
        {
            SetLocalVarInt("Lever", 1);
            for (int i = 22; i <= 26 && i >= 22; i++)
            {
                SetEntityInteractionDisabled("lever_simple01_"+i, false);
            }
            return;
        }
    }
}

(This post was last modified: 05-01-2011, 11:34 PM by Kyle.)
05-01-2011, 11:32 PM
Find
Tanshaydar Offline
From Beyond

Posts: 3,085
Threads: 17
Joined: Mar 2009
Reputation: 67
#2
RE: Lever-Pulling Combination Help

I have a puzzle and nicely coded and it works. To give an example:
removed code

Simply, I have an int variable and when buttons pressed in order it counts, and when filan button pressed it checks whether int value is expected or not.

(This post was last modified: 05-02-2011, 12:15 AM by Tanshaydar.)
05-01-2011, 11:37 PM
Website Find
Kyle Offline
Posting Freak

Posts: 911
Threads: 36
Joined: Sep 2010
Reputation: 7
#3
RE: Lever-Pulling Combination Help

I don't really understand what the script is trying to show in comparison to mine, but I'm adding debug messages to zero in on the issue.

I think I found the problem, or at least part of it...

(This post was last modified: 05-01-2011, 11:58 PM by Kyle.)
05-01-2011, 11:53 PM
Find
Tanshaydar Offline
From Beyond

Posts: 3,085
Threads: 17
Joined: Mar 2009
Reputation: 67
#4
RE: Lever-Pulling Combination Help

Step by step:

Assume you have password 4 5 2 1 3

Pulled 1: If variable int is 3 then set the int variable to 4; if not set the int variable to 0.
Pulled 2: If variable int is 2 then set the int variable to 3; if not set the int variable to 0.
Pulled 3: If variable int is 4 then do whatever needed; if not set the int variable to 0.
Pulled 4: Set the int variable to 1.
Pulled 5: If variable int is 1 then set the int variable to 2; if not set the int variable to 0.

05-02-2011, 12:09 AM
Website Find
Kyle Offline
Posting Freak

Posts: 911
Threads: 36
Joined: Sep 2010
Reputation: 7
#5
RE: Lever-Pulling Combination Help

It's alright, I got most if it fixed with my handy-dandy debug messages. Big Grin

I got it to where you pull all the levers in the correct order and you can't interact with them anymore, I can do the rest. Thanks for your help! Smile

05-02-2011, 12:13 AM
Find




Users browsing this thread: 2 Guest(s)