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 Why won't this script work?
ferryadams10 Offline
Senior Member

Posts: 288
Threads: 40
Joined: Apr 2011
Reputation: 19
#1
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. Sad

PHP Code: (Select All)
////////////////////////////
// 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// 

Got a nice sofa
Please come and have a seat for a while

12-17-2011, 04:29 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#2
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

PHP Code: (Select All)
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

(This post was last modified: 12-17-2011, 05:18 PM by palistov.)
12-17-2011, 05:18 PM
Find
Dobbydoo Offline
Member

Posts: 50
Threads: 6
Joined: Aug 2011
Reputation: 0
#3
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

PHP Code: (Select All)
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.

12-17-2011, 05:29 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
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.

PHP Code: (Select All)
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.

Tutorials: From Noob to Pro
(This post was last modified: 12-17-2011, 06:53 PM by Your Computer.)
12-17-2011, 06:16 PM
Website Find
ferryadams10 Offline
Senior Member

Posts: 288
Threads: 40
Joined: Apr 2011
Reputation: 19
#5
RE: Why won't this script work?

Thanks allot.

It worked Big Grin

Got a nice sofa
Please come and have a seat for a while

12-17-2011, 06:52 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#6
RE: Why won't this script work?

Your Computer, just showing him the simplest and easiest-to-understand solution Tongue

(This post was last modified: 12-17-2011, 07:10 PM by palistov.)
12-17-2011, 07:10 PM
Find
Dobbydoo Offline
Member

Posts: 50
Threads: 6
Joined: Aug 2011
Reputation: 0
#7
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.

PHP Code: (Select All)
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: (Select All)
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.
(This post was last modified: 12-17-2011, 09:21 PM by Dobbydoo.)
12-17-2011, 07:50 PM
Find
ferryadams10 Offline
Senior Member

Posts: 288
Threads: 40
Joined: Apr 2011
Reputation: 19
#8
RE: Why won't this script work?

Haha thanks Dobbydoo but it was already working ^^

Thanks for being so helpfull against me anyways Smile

Got a nice sofa
Please come and have a seat for a while

12-21-2011, 08:29 PM
Find




Users browsing this thread: 1 Guest(s)