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


Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple Issues Help Creating A Lever Puzzle
JenniferOrange Offline
Senior Member

Posts: 424
Threads: 43
Joined: Jun 2011
Reputation: 33
#1
Creating A Lever Puzzle

I'm trying to create a lever puzzle, using either the guiding rod machine or the lever one, it doesn't matter to me. Whichever is easier, I guess.
I want to either put levers in a certain up/down state or put the three guiding rods into the machine to cause a screen shake, which in turn causes the huge castle gate to open. I can handle the last part, I'm just clueless on levers. I can do one, but I can't do multiple to save my life. A script or tutorial/thread link would be helpful. Thankyou :]

Ba-da bing, ba-da boom.
11-21-2011, 11:10 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Creating A Lever Puzzle


  1. Set connection state callbacks to all levers.
  2. Create a function that checks the state of all levers.
  3. Create a function to call when all levers have been set by the player.
  4. Save the state of each lever when the callback is called.
    1. Call the function from #2 after storing the state of the lever, within the connection state callback.
  5. If all levers are in the state you want them to be, call the function from #3.

Tutorials: From Noob to Pro
11-22-2011, 12:02 AM
Website Find
BlueFury Offline
Senior Member

Posts: 470
Threads: 30
Joined: May 2011
Reputation: 9
#3
RE: Creating A Lever Puzzle

(11-22-2011, 12:02 AM)Your Computer Wrote:
  1. Set connection state callbacks to all levers.
  2. Create a function that checks the state of all levers.
  3. Create a function to call when all levers have been set by the player.
  4. Save the state of each lever when the callback is called.
    1. Call the function from #2 after storing the state of the lever, within the connection state callback.
  5. If all levers are in the state you want them to be, call the function from #3.

thanks bro


Sticks and stones may break our bones, but words will break our hearts. – Robert Fulghum
11-22-2011, 12:08 AM
Find
JenniferOrange Offline
Senior Member

Posts: 424
Threads: 43
Joined: Jun 2011
Reputation: 33
#4
RE: Creating A Lever Puzzle

(11-22-2011, 12:02 AM)Your Computer Wrote:
  1. Set connection state callbacks to all levers.
  2. Create a function that checks the state of all levers.
  3. Create a function to call when all levers have been set by the player.
  4. Save the state of each lever when the callback is called.
  5. Call the function from #2 after storing the state of the lever, within the connection state callback.
[*]If all levers are in the state you want them to be, call the function from #3.
I'm sorry is it just me that finds that confusing? Sad maybe a script example?


Ba-da bing, ba-da boom.
11-22-2011, 01:12 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#5
RE: Creating A Lever Puzzle

(11-22-2011, 01:12 AM)JenniferOrange Wrote: maybe a script example?

PHP Code: (Select All)
/*

   ***** Warning: untested code *****

   Assuming only two levers are present in map.
   First lever name: "lever_1"
   Second lever name: "lever_2"
   Assuming global script variables "lever_1_state" and "lever_2_state" have been defined.

*/

void OnStart()
{
    
SetEntityConnectionStateChangeCallback("lever_1""StoreCheckLeverState");
    
SetEntityConnectionStateChangeCallback("lever_2""StoreCheckLeverState");
}

void CheckLeverStates()
{
    if (
GetLocalVarInt("lever_1") == lever_1_state
     
&& GetLocalVarInt("lever_2") == lever_2_state)
    {
        
PerformLeverTaskCompleted();
    }
}

void PerformLeverTaskCompleted()
{
    
// Do something...
}

void StoreCheckLeverState(string &in entityint state)
{
    
SetLocalVarInt(entitystate);
    
CheckLeverStates();


Tutorials: From Noob to Pro
11-22-2011, 01:49 AM
Website Find
JenniferOrange Offline
Senior Member

Posts: 424
Threads: 43
Joined: Jun 2011
Reputation: 33
#6
RE: Creating A Lever Puzzle

(11-22-2011, 01:49 AM)Your Computer Wrote:
(11-22-2011, 01:12 AM)JenniferOrange Wrote: maybe a script example?

PHP Code: (Select All)
/*

   ***** Warning: untested code *****

   Assuming only two levers are present in map.
   First lever name: "lever_1"
   Second lever name: "lever_2"
   Assuming global script variables "lever_1_state" and "lever_2_state" have been defined.

*/

void OnStart()
{
    
SetEntityConnectionStateChangeCallback("lever_1""StoreCheckLeverState");
    
SetEntityConnectionStateChangeCallback("lever_2""StoreCheckLeverState");
}

void CheckLeverStates()
{
    if (
GetLocalVarInt("lever_1") == lever_1_state
     
&& GetLocalVarInt("lever_2") == lever_2_state)
    {
        
PerformLeverTaskCompleted();
    }
}

void PerformLeverTaskCompleted()
{
    
// Do something...
}

void StoreCheckLeverState(string &in entityint state)
{
    
SetLocalVarInt(entitystate);
    
CheckLeverStates();


Thank you, I'll try this! Which function do I use to define the global variables and where should I put them/it?

Ba-da bing, ba-da boom.
11-22-2011, 02:04 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#7
RE: Creating A Lever Puzzle

(11-22-2011, 02:04 AM)JenniferOrange Wrote: Thank you, I'll try this! Which function do I use to define the global variables and where should I put them/it?

Technically, you don't need to; though, it's just an example, the variable names being placeholders. Replace whatever to suit your needs.

Tutorials: From Noob to Pro
(This post was last modified: 11-22-2011, 05:13 AM by Your Computer.)
11-22-2011, 05:13 AM
Website Find
teddan50 Offline
Junior Member

Posts: 15
Threads: 2
Joined: Dec 2011
Reputation: 0
#8
RE: Creating A Lever Puzzle

My script does for some reason don't work. I have setted all of the levers on stuck in max and InteractionDisablesStuck, so when I have pulled the right levers they are in the wanted positions, but still the "PerformLeverTaskCompleted" doesn't start...

void OnStart()
{
SetEntityConnectionStateChangeCallback("lever_1", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_2", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_3", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_4", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_5", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_6", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_7", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_8", "StoreCheckLeverState");
}

void CheckLeverStates()
{
if (GetLocalVarInt("lever_1") == 0
&& GetLocalVarInt("lever_2") == 1
&& GetLocalVarInt("lever_3") == 0
&& GetLocalVarInt("lever_4") == 1
&& GetLocalVarInt("lever_5") == 0
&& GetLocalVarInt("lever_6") == 1
&& GetLocalVarInt("lever_7") == 1
&& GetLocalVarInt("lever_8") == 0)
{
PerformLeverTaskCompleted();
}
}
void PerformLeverTaskCompleted()
{
SetSwingDoorLocked("door1", false, false);
SetSwingDoorClosed("door1", false, false);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
PlaySoundAtEntity("", "quest_completed.snt", "Player", 0.5f, false);
StartEffectFlash(1, 0.4, 1);
}

void StoreCheckLeverState(string &in entity, int state)
{
SetLocalVarInt("lever_1", 0);
SetLocalVarInt("lever_2", 1);
SetLocalVarInt("lever_3", 0);
SetLocalVarInt("lever_4", 1);
SetLocalVarInt("lever_5", 0);
SetLocalVarInt("lever_6", 1);
SetLocalVarInt("lever_7", 1);
SetLocalVarInt("lever_8", 0);
CheckLeverStates();
}
12-12-2011, 08:58 PM
Find
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
#9
RE: Creating A Lever Puzzle

You're not supposed to do this:
PHP Code: (Select All)
void StoreCheckLeverState(string &in entityint state)
 {
     
SetLocalVarInt("lever_1"0);
     
SetLocalVarInt("lever_2"1);
     
SetLocalVarInt("lever_3"0);
     
SetLocalVarInt("lever_4"1);
     
SetLocalVarInt("lever_5"0);
     
SetLocalVarInt("lever_6"1);
     
SetLocalVarInt("lever_7"1);
     
SetLocalVarInt("lever_8"0);
     
CheckLeverStates();
 } 

You should replace that with this:

PHP Code: (Select All)
void StoreCheckLeverState(string &in entityint state)
 {
     
SetLocalVarInt(entitystate);
     
CheckLeverStates();
 } 

What you are doing by changing that is creating a random variable with the entities name(lever_1, lever_2 etc.), and saving that levers state. In the function CheckLeverStates() you will check the state of each and if the state of each one corresponds to the expected it will trigger the final function.


Today I dreamt the life I could live forever. You only know that when you feel it for you know not what you like until you've experienced it.
(This post was last modified: 12-12-2011, 09:15 PM by nemesis567.)
12-12-2011, 09:12 PM
Find
teddan50 Offline
Junior Member

Posts: 15
Threads: 2
Joined: Dec 2011
Reputation: 0
#10
RE: Creating A Lever Puzzle

(12-12-2011, 09:12 PM)nemesis567 Wrote: You're not supposed to do this:
PHP Code: (Select All)
void StoreCheckLeverState(string &in entityint state

SetLocalVarInt("lever_1"0); 
SetLocalVarInt("lever_2"1); 
SetLocalVarInt("lever_3"0); 
SetLocalVarInt("lever_4"1); 
SetLocalVarInt("lever_5"0); 
SetLocalVarInt("lever_6"1); 
SetLocalVarInt("lever_7"1); 
SetLocalVarInt("lever_8"0); 
CheckLeverStates(); 



You should replace that with this:

PHP Code: (Select All)
void StoreCheckLeverState(string &in entityint state

SetLocalVarInt(entitystate); 
CheckLeverStates(); 



What you are doing by changing that is creating a random variable with the entities name(lever_1, lever_2 etc.), and saving that levers state. In the function CheckLeverStates() you will check the state of each and if the state of each one corresponds to the expected it will trigger the final function.


Ok, I understand...

But I still have a problem with the "complete" part. I can't seem to get the door to lock itself (yes I have checked the locked box). And the sound and light effects doesn't start either...

12-12-2011, 10:01 PM
Find




Users browsing this thread: 2 Guest(s)