JenniferOrange
Senior Member
Posts: 424
Threads: 43
Joined: Jun 2011
Reputation:
33
|
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 |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
RE: Creating A Lever Puzzle
- Set connection state callbacks to all levers.
- Create a function that checks the state of all levers.
- Create a function to call when all levers have been set by the player.
- Save the state of each lever when the callback is called.
- 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.
|
|
11-22-2011, 12:02 AM |
|
BlueFury
Senior Member
Posts: 470
Threads: 30
Joined: May 2011
Reputation:
9
|
RE: Creating A Lever Puzzle
(11-22-2011, 12:02 AM)Your Computer Wrote:
- Set connection state callbacks to all levers.
- Create a function that checks the state of all levers.
- Create a function to call when all levers have been set by the player.
- Save the state of each lever when the callback is called.
- 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.
thanks bro
Sticks and stones may break our bones, but words will break our hearts. – Robert Fulghum
|
|
11-22-2011, 12:08 AM |
|
JenniferOrange
Senior Member
Posts: 424
Threads: 43
Joined: Jun 2011
Reputation:
33
|
RE: Creating A Lever Puzzle
(11-22-2011, 12:02 AM)Your Computer Wrote:
- Set connection state callbacks to all levers.
- Create a function that checks the state of all levers.
- Create a function to call when all levers have been set by the player.
- Save the state of each lever when the callback is called.
- 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? maybe a script example?
Ba-da bing, ba-da boom.
|
|
11-22-2011, 01:12 AM |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
RE: Creating A Lever Puzzle
(11-22-2011, 01:12 AM)JenniferOrange Wrote: maybe a script example?
/*
***** 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 entity, int state) { SetLocalVarInt(entity, state); CheckLeverStates(); }
|
|
11-22-2011, 01:49 AM |
|
JenniferOrange
Senior Member
Posts: 424
Threads: 43
Joined: Jun 2011
Reputation:
33
|
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?
/*
***** 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 entity, int state) { SetLocalVarInt(entity, state); 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 |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
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.
(This post was last modified: 11-22-2011, 05:13 AM by Your Computer.)
|
|
11-22-2011, 05:13 AM |
|
teddan50
Junior Member
Posts: 15
Threads: 2
Joined: Dec 2011
Reputation:
0
|
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 |
|
nemesis567
Posting Freak
Posts: 874
Threads: 65
Joined: May 2011
Reputation:
10
|
RE: Creating A Lever Puzzle
You're not supposed to do this:
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(); }
You should replace that with this:
void StoreCheckLeverState(string &in entity, int state) { SetLocalVarInt(entity, state); 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 |
|
teddan50
Junior Member
Posts: 15
Threads: 2
Joined: Dec 2011
Reputation:
0
|
RE: Creating A Lever Puzzle
(12-12-2011, 09:12 PM)nemesis567 Wrote: You're not supposed to do this:
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(); }
You should replace that with this:
void StoreCheckLeverState(string &in entity, int state) { SetLocalVarInt(entity, state); 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 |
|
|