ferryadams10
Senior Member
Posts: 288
Threads: 40
Joined: Apr 2011
Reputation:
19
|
Why won't this script work?
Hi guys.
What I'm trying to do is make the SlideDoor2 go open when I've set all levers in a proper order.
lever_1, 3 and 4 should be down
lever_2 and 5 should be up.
But.. Now the PerformLeverTaskCompleted starts working as soon as I pull just a random lever.
Please help me to make the SlideDoor2 open when I put em in the right order.
//////////////////////////// // Run first time starting map void OnStart() { //START LEVER PUZZLE// SetEntityConnectionStateChangeCallback("lever_1", "StoreCheckLeverState"); SetEntityConnectionStateChangeCallback("lever_2", "StoreCheckLeverState"); SetEntityConnectionStateChangeCallback("lever_3", "StoreCheckLeverState"); SetEntityConnectionStateChangeCallback("lever_4", "StoreCheckLeverState"); SetEntityConnectionStateChangeCallback("lever_5", "StoreCheckLeverState"); SetEntityConnectionStateChangeCallback("lever_6", "StoreCheckLeverState"); //END LEVER PUZZLE// } //START LEVER PUZZLE// void CheckLeverStates() { if (GetLocalVarInt("lever_1") == -1 && GetLocalVarInt("lever_2") == 1 && GetLocalVarInt("lever_3") == -1 && GetLocalVarInt("lever_4") == -1 && GetLocalVarInt("lever_5") == 1 && GetLocalVarInt("lever_6") == 1) { PerformLeverTaskCompleted(); } } void PerformLeverTaskCompleted() { SetMoveObjectStateExt("SlideDoor2", 1.0f, 1.0f, 1.0f, 0.0f, false); } void StoreCheckLeverState(string &in entity, int state) { SetLocalVarInt("lever_1", -1); SetLocalVarInt("lever_2", 1); SetLocalVarInt("lever_3", -1); SetLocalVarInt("lever_4", -1); SetLocalVarInt("lever_5", 1); SetLocalVarInt("lever_6", 1); CheckLeverStates(); } //END LEVER PUZZLE//
Got a nice sofa
Please come and have a seat for a while
|
|
12-17-2011, 04:29 PM |
|
palistov
Posting Freak
Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation:
57
|
RE: Why won't this script work?
Your syntax is all correct but your semantics is all out of whack. Semantics is basically programming "grammar", while syntax is programming "spelling". Your code is syntactically correct, but if you take a look at your function StoreCheckLeverState, you'll notice that no matter what lever is pulled, the variables are all set to the correct state. Hence, the player can pull any one lever and solve the puzzle. To solve this, use this function instead
void StoreCheckLeverState(string &in entity, int state) { if(entity == "lever_1") SetLocalVarInt("lever_1", state); if(entity == "lever_2") SetLocalVarInt("lever_2", state); if(entity == "lever_3") SetLocalVarInt("lever_3", state); if(entity == "lever_4") SetLocalVarInt("lever_4", state); if(entity == "lever_5") SetLocalVarInt("lever_5", state); if(entity == "lever_6") SetLocalVarInt("lever_6", state); CheckLeverStates(); }
Good luck
(This post was last modified: 12-17-2011, 05:18 PM by palistov.)
|
|
12-17-2011, 05:18 PM |
|
Dobbydoo
Member
Posts: 50
Threads: 6
Joined: Aug 2011
Reputation:
0
|
RE: Why won't this script work?
(12-17-2011, 05:18 PM)palistov Wrote: Your syntax is all correct but your semantics is all out of whack. Semantics is basically programming "grammar", while syntax is programming "spelling". Your code is syntactically correct, but if you take a look at your function StoreCheckLeverState, you'll notice that no matter what lever is pulled, the variables are all set to the correct state. Hence, the player can pull any one lever and solve the puzzle. To solve this, use this function instead
void StoreCheckLeverState(string &in entity, int state) { if(entity == "lever_1") SetLocalVarInt("lever_1", state); if(entity == "lever_2") SetLocalVarInt("lever_2", state); if(entity == "lever_3") SetLocalVarInt("lever_3", state); if(entity == "lever_4") SetLocalVarInt("lever_4", state); if(entity == "lever_5") SetLocalVarInt("lever_5", state); if(entity == "lever_6") SetLocalVarInt("lever_6", state); CheckLeverStates(); }
Good luck It would be much easier to have only one variable for all levers. Then every time you pull a lever you add one to the variable and when it reaches 6 the puzzle is completed.
|
|
12-17-2011, 05:29 PM |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
RE: Why won't this script work?
There's no point to check for the lever name from the entity variable if the local map variable carries the same name.
void StoreCheckLeverState(string &in entity, int state) { SetLocalVarInt(entity, state); CheckLeverStates(); }
(12-17-2011, 05:29 PM)Dobbydoo Wrote: It would be much easier to have only one variable for all levers. Then every time you pull a lever you add one to the variable and when it reaches 6 the puzzle is completed.
That would be error prone. Even if we set a stuck state for each lever when it gets pulled correctly, you'd still be adding 1 for when it gets pulled in the opposite, undesired direction.
(This post was last modified: 12-17-2011, 06:53 PM by Your Computer.)
|
|
12-17-2011, 06:16 PM |
|
ferryadams10
Senior Member
Posts: 288
Threads: 40
Joined: Apr 2011
Reputation:
19
|
RE: Why won't this script work?
Thanks allot.
It worked
Got a nice sofa
Please come and have a seat for a while
|
|
12-17-2011, 06:52 PM |
|
palistov
Posting Freak
Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation:
57
|
RE: Why won't this script work?
Your Computer, just showing him the simplest and easiest-to-understand solution
(This post was last modified: 12-17-2011, 07:10 PM by palistov.)
|
|
12-17-2011, 07:10 PM |
|
Dobbydoo
Member
Posts: 50
Threads: 6
Joined: Aug 2011
Reputation:
0
|
RE: Why won't this script work?
(12-17-2011, 06:16 PM)Your Computer Wrote: There's no point to check for the lever name from the entity variable if the local map variable carries the same name.
void StoreCheckLeverState(string &in entity, int state) { SetLocalVarInt(entity, state); CheckLeverStates(); }
(12-17-2011, 05:29 PM)Dobbydoo Wrote: It would be much easier to have only one variable for all levers. Then every time you pull a lever you add one to the variable and when it reaches 6 the puzzle is completed.
That would be error prone. Even if we set a stuck state for each lever when it gets pulled correctly, you'd still be adding 1 for when it gets pulled in the opposite, undesired direction. Not if he only added to the variable when it was in the right state, and maybe made it stuck when in that state.
Like this:
if(alState == 1) { SetLeverStuckState(string& asName, int alState, bool abEffects); AddLocalVarInt(string& asName, int alVal); }
EDIT: And of course when not being in the right state one would be removed from the variable.
(This post was last modified: 12-17-2011, 09:21 PM by Dobbydoo.)
|
|
12-17-2011, 07:50 PM |
|
ferryadams10
Senior Member
Posts: 288
Threads: 40
Joined: Apr 2011
Reputation:
19
|
RE: Why won't this script work?
Haha thanks Dobbydoo but it was already working ^^
Thanks for being so helpfull against me anyways
Got a nice sofa
Please come and have a seat for a while
|
|
12-21-2011, 08:29 PM |
|
|