Frictional Games Forum (read-only)

Full Version: Why won't this script work?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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. Sad

PHP Code:
////////////////////////////
// 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.0f1.0f1.0f0.0ffalse);
}
void StoreCheckLeverState(string &in entityint 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// 
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

PHP Code:
void StoreCheckLeverState(string &in entityint 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 Smile
(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

PHP Code:
void StoreCheckLeverState(string &in entityint 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 Smile
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.

There's no point to check for the lever name from the entity variable if the local map variable carries the same name.

PHP Code:
void StoreCheckLeverState(string &in entityint state)
{
SetLocalVarInt(entitystate);
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.
Thanks allot.

It worked Big Grin
Your Computer, just showing him the simplest and easiest-to-understand solution Tongue
(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.

PHP Code:
void StoreCheckLeverState(string &in entityint state)
{
SetLocalVarInt(entitystate);
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:
PHP Code:
if(alState == 1)
 {
 
SetLeverStuckState(stringasNameint alStatebool abEffects);
 
AddLocalVarInt(stringasNameint alVal);
 } 

EDIT: And of course when not being in the right state one would be removed from the variable.
Haha thanks Dobbydoo but it was already working ^^

Thanks for being so helpfull against me anyways Smile