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
Script Help Need help to make a lever puzzle
Tripication Offline
Member

Posts: 172
Threads: 19
Joined: Dec 2011
Reputation: 6
#21
RE: Need help to make a lever puzzle

(01-15-2012, 11:55 AM)Shadowfied Wrote: Uhm..I thought I already told you I solved it?

Statyk had put "SetLeverStuckState("LEVER4", 1, true);" in every function, removing all of those and adding your "SetLeverStuckState" scripts at the end solved it. There was no reason (not that I understand anyway) to make them stuck all the time and using the InteractDisablesStuck checkbox for this situation.
Oh, thats good then. NVM about the last post.
And good luck with the rest of your story

[Image: speedart__2___yoshimitsu_by_kamofudge-d4yo6kk.png]
01-15-2012, 12:00 PM
Find
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#22
RE: Need help to make a lever puzzle

(01-15-2012, 11:56 AM)Your Computer Wrote: Here's a more efficient way of doing it (though entirely untested).

PHP Code: (Select All)
const string[] lever_names = {"LEVER1""LEVER2""LEVER3""LEVER4"}
const 
int[] desired_lever_states = {11, -11}

/******************************************************************************/

void OnStart()
{
    
SetEntityConnectionStateChangeCallback("LEVER1""lever_func");
    
SetEntityConnectionStateChangeCallback("LEVER2""lever_func");
    
SetEntityConnectionStateChangeCallback("LEVER3""lever_func");
    
SetEntityConnectionStateChangeCallback("LEVER4""lever_func");

    
SetLocalVarInt("LEVER1"0);
    
SetLocalVarInt("LEVER2"0);
    
SetLocalVarInt("LEVER3"0);
    
SetLocalVarInt("LEVER4"0);
}

/******************************************************************************/

void lever_func(string &in asEntityint alState)
{
    if (
GetLocalVarInt("LEVER_PUZZLE_COMPLETE") == 1)
        return;

    
SetLocalVarInt(asEntityalState);    
    
CheckFunction();
}

/******************************************************************************/

void CheckFunction()
{
    for (
int i 0lever_names.length(); ++i)
    {
        if (
GetLocalVarInt(lever_names[i]) != desired_lever_states[i])
            return;
        else
        {
            
SetLeverStuckState(lever_names[i], desired_lever_states[i], true);
            
SetEntityConnectionStateChangeCallback(lever_names[i], "");
        }
    }
    
    
GiveSanityBoost();
    
SetSwingDoorLocked("LEVERDOOR"falsetrue);
    
SetLocalVarInt("LEVER_PUZZLE_COMPLETE"1);

Wow that's a lot shorter. I appreciate it, although for now I'm gonna stick with what I understand myself so I have use for it and know what I'm doing.


Thank you very much Tripication.

Current - Castle Darkuan
Other - F*cked Map
(This post was last modified: 01-15-2012, 12:02 PM by Shadowfied.)
01-15-2012, 12:01 PM
Find
Tripication Offline
Member

Posts: 172
Threads: 19
Joined: Dec 2011
Reputation: 6
#23
RE: Need help to make a lever puzzle

Ahh, that was fun. Time for tea.

[Image: speedart__2___yoshimitsu_by_kamofudge-d4yo6kk.png]
01-15-2012, 12:02 PM
Find
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#24
RE: Need help to make a lever puzzle

(01-15-2012, 12:02 PM)Tripication Wrote: Ahh, that was fun. Time for tea.
Enjoy it. ;]

Current - Castle Darkuan
Other - F*cked Map
01-15-2012, 12:03 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#25
RE: Need help to make a lever puzzle

(01-15-2012, 11:56 AM)Your Computer Wrote: Here's a more efficient way of doing it (though entirely untested).

PHP Code: (Select All)
const string[] lever_names = {"LEVER1""LEVER2""LEVER3""LEVER4"}
const 
int[] desired_lever_states = {11, -11}

/******************************************************************************/

void OnStart()
{
    
SetEntityConnectionStateChangeCallback("LEVER1""lever_func");
    
SetEntityConnectionStateChangeCallback("LEVER2""lever_func");
    
SetEntityConnectionStateChangeCallback("LEVER3""lever_func");
    
SetEntityConnectionStateChangeCallback("LEVER4""lever_func");

    
SetLocalVarInt("LEVER1"0);
    
SetLocalVarInt("LEVER2"0);
    
SetLocalVarInt("LEVER3"0);
    
SetLocalVarInt("LEVER4"0);
}

/******************************************************************************/

void lever_func(string &in asEntityint alState)
{
    if (
GetLocalVarInt("LEVER_PUZZLE_COMPLETE") == 1)
        return;

    
SetLocalVarInt(asEntityalState);    
    
CheckFunction();
}

/******************************************************************************/

void CheckFunction()
{
    for (
int i 0lever_names.length(); ++i)
    {
        if (
GetLocalVarInt(lever_names[i]) != desired_lever_states[i])
            return;
        else
        {
            
SetLeverStuckState(lever_names[i], desired_lever_states[i], true);
            
SetEntityConnectionStateChangeCallback(lever_names[i], "");
        }
    }
    
    
GiveSanityBoost();
    
SetSwingDoorLocked("LEVERDOOR"falsetrue);
    
SetLocalVarInt("LEVER_PUZZLE_COMPLETE"1);




Goodness gracious great balls of fire, this is ridiculous... XD I have a lot to learn! I might give this a whirl to try it out. Also need to find time to watch your scripting tutorial. And guys, I'm really NOT the best scripter. I'm glad you appreciate the effort and stuff but I'm still a newbie to this stuff. >>; I'm glad you liked Hunter though =P I think I'm going to continue it in Cry's 2nd 24-Hour installment.


Also, instead of setting new levers and whatnot, in the "CheckFunction", add this (all issues solved when you can't touch the levers after completion):

CheckFunction()
{
SetEntityInteractionDisabled("LEVER1", true);
SetEntityInteractionDisabled("LEVER2", true);
SetEntityInteractionDisabled("LEVER3", true);
SetEntityInteractionDisabled("LEVER4", true);
}
(This post was last modified: 01-15-2012, 03:23 PM by Statyk.)
01-15-2012, 03:13 PM
Find
Inurias Offline
Junior Member

Posts: 20
Threads: 0
Joined: Jan 2012
Reputation: 2
#26
RE: Need help to make a lever puzzle

(01-15-2012, 03:13 PM)Statyk Wrote:
(01-15-2012, 11:56 AM)Your Computer Wrote: Here's a more efficient way of doing it (though entirely untested).

PHP Code: (Select All)
const string[] lever_names = {"LEVER1""LEVER2""LEVER3""LEVER4"}
const 
int[] desired_lever_states = {11, -11}

/******************************************************************************/

void OnStart()
{
SetEntityConnectionStateChangeCallback("LEVER1""lever_func");
SetEntityConnectionStateChangeCallback("LEVER2""lever_func");
SetEntityConnectionStateChangeCallback("LEVER3""lever_func");
SetEntityConnectionStateChangeCallback("LEVER4""lever_func");

SetLocalVarInt("LEVER1"0);
SetLocalVarInt("LEVER2"0);
SetLocalVarInt("LEVER3"0);
SetLocalVarInt("LEVER4"0);
}

/******************************************************************************/

void lever_func(string &in asEntityint alState)
{
if (
GetLocalVarInt("LEVER_PUZZLE_COMPLETE") == 1)
return;

SetLocalVarInt(asEntityalState);
CheckFunction();
}

/******************************************************************************/

void CheckFunction()
{
for (
int i 0lever_names.length(); ++i)
{
if (
GetLocalVarInt(lever_names[i]) != desired_lever_states[i])
return;
else
{
SetLeverStuckState(lever_names[i], desired_lever_states[i], true);
SetEntityConnectionStateChangeCallback(lever_names[i], "");
}
}

GiveSanityBoost();
SetSwingDoorLocked("LEVERDOOR"falsetrue);
SetLocalVarInt("LEVER_PUZZLE_COMPLETE"1);




Goodness gracious great balls of fire, this is ridiculous... XD I have a lot to learn! I might give this a whirl to try it out. Also need to find time to watch your scripting tutorial. And guys, I'm really NOT the best scripter. I'm glad you appreciate the effort and stuff but I'm still a newbie to this stuff. >>; I'm glad you liked Hunter though =P I think I'm going to continue it in Cry's 2nd 24-Hour installment.


Also, instead of setting new levers and whatnot, in the "CheckFunction", add this (all issues solved when you can't touch the levers after completion):

CheckFunction()
{
SetEntityInteractionDisabled("LEVER1", true);
SetEntityInteractionDisabled("LEVER2", true);
SetEntityInteractionDisabled("LEVER3", true);
SetEntityInteractionDisabled("LEVER4", true);
}
If you are really going for shortness, I just made up an even shorter version (which works):

string[] vars = {"", "", "", "", ""};

void OnStart()
{
    for (int i = 1; i <= 4; i++)
        SetEntityConnectionStateChangeCallback("LEVER" + i, "LeverCallback");
}

void LeverCallback(string &in asEntity, int alState)
{

    if (alState != 0)
    {
        for (int i = 1; i <= 4; i++)
        {
                if (StringContains(asEntity, "" + i))
                {
                    vars[i] = "b" + asEntity;
                    SetLocalVarInt(vars[i], alState);
                    SetLeverStuckState(asEntity, alState, true);
                    break;
                }
        }
    }

    if (GetLocalVarInt(vars[1]) == 1 && GetLocalVarInt(vars[2]) == 1 && GetLocalVarInt(vars[3]) == -1 && GetLocalVarInt(vars[4]) == 1)
        DoMyStuff();
}

void DoMyStuff()
{
     GiveSanityBoost();
                 SetSwingDoorLocked("LEVERDOOR", false, true);

     for (int l = 1; l <= 4; l++)
        SetEntityInteractionDisabled("LEVER" + l, true);
}

- Inurias
01-16-2012, 09:11 PM
Find
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#27
RE: Need help to make a lever puzzle

(01-16-2012, 09:11 PM)Inurias Wrote:
(01-15-2012, 03:13 PM)Statyk Wrote:
(01-15-2012, 11:56 AM)Your Computer Wrote: Here's a more efficient way of doing it (though entirely untested).

PHP Code: (Select All)
const string[] lever_names = {"LEVER1""LEVER2""LEVER3""LEVER4"}
const 
int[] desired_lever_states = {11, -11}

/******************************************************************************/

void OnStart()
{
SetEntityConnectionStateChangeCallback("LEVER1""lever_func");
SetEntityConnectionStateChangeCallback("LEVER2""lever_func");
SetEntityConnectionStateChangeCallback("LEVER3""lever_func");
SetEntityConnectionStateChangeCallback("LEVER4""lever_func");

SetLocalVarInt("LEVER1"0);
SetLocalVarInt("LEVER2"0);
SetLocalVarInt("LEVER3"0);
SetLocalVarInt("LEVER4"0);
}

/******************************************************************************/

void lever_func(string &in asEntityint alState)
{
if (
GetLocalVarInt("LEVER_PUZZLE_COMPLETE") == 1)
return;

SetLocalVarInt(asEntityalState);
CheckFunction();
}

/******************************************************************************/

void CheckFunction()
{
for (
int i 0lever_names.length(); ++i)
{
if (
GetLocalVarInt(lever_names[i]) != desired_lever_states[i])
return;
else
{
SetLeverStuckState(lever_names[i], desired_lever_states[i], true);
SetEntityConnectionStateChangeCallback(lever_names[i], "");
}
}

GiveSanityBoost();
SetSwingDoorLocked("LEVERDOOR"falsetrue);
SetLocalVarInt("LEVER_PUZZLE_COMPLETE"1);




Goodness gracious great balls of fire, this is ridiculous... XD I have a lot to learn! I might give this a whirl to try it out. Also need to find time to watch your scripting tutorial. And guys, I'm really NOT the best scripter. I'm glad you appreciate the effort and stuff but I'm still a newbie to this stuff. >>; I'm glad you liked Hunter though =P I think I'm going to continue it in Cry's 2nd 24-Hour installment.


Also, instead of setting new levers and whatnot, in the "CheckFunction", add this (all issues solved when you can't touch the levers after completion):

CheckFunction()
{
SetEntityInteractionDisabled("LEVER1", true);
SetEntityInteractionDisabled("LEVER2", true);
SetEntityInteractionDisabled("LEVER3", true);
SetEntityInteractionDisabled("LEVER4", true);
}
If you are really going for shortness, I just made up an even shorter version (which works):

string[] vars = {"", "", "", "", ""};

void OnStart()
{
    for (int i = 1; i <= 4; i++)
        SetEntityConnectionStateChangeCallback("LEVER" + i, "LeverCallback");
}

void LeverCallback(string &in asEntity, int alState)
{

    if (alState != 0)
    {
        for (int i = 1; i <= 4; i++)
        {
                if (StringContains(asEntity, "" + i))
                {
                    vars[i] = "b" + asEntity;
                    SetLocalVarInt(vars[i], alState);
                    SetLeverStuckState(asEntity, alState, true);
                    break;
                }
        }
    }

    if (GetLocalVarInt(vars[1]) == 1 && GetLocalVarInt(vars[2]) == 1 && GetLocalVarInt(vars[3]) == -1 && GetLocalVarInt(vars[4]) == 1)
        DoMyStuff();
}

void DoMyStuff()
{
     GiveSanityBoost();
                 SetSwingDoorLocked("LEVERDOOR", false, true);

     for (int l = 1; l <= 4; l++)
        SetEntityInteractionDisabled("LEVER" + l, true);
}

- Inurias
I wish I understood that..


Current - Castle Darkuan
Other - F*cked Map
01-17-2012, 08:15 AM
Find




Users browsing this thread: 3 Guest(s)