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
[Solved] Puzzle Script Problem?
Vale Offline
Member

Posts: 92
Threads: 13
Joined: Mar 2014
Reputation: 7
#1
[Solved] Puzzle Script Problem?

Alright, few things here.

First off is the problem I'm having.
Im creating a script for a puzzle in my custom story which works smoothly for the most part. The only error is in the fact that you can still move the pieces of the puzzle once it's completed, though the if()'s in the script should prevent that.
Here is the script below.

Spoiler below!

void OnStart()
{
AddEntityCollideCallback("Player", "script_shelf_fall", "func_shelf_fall", true, 1);
AddEntityCollideCallback("shelf_fall", "shelf_impact_area", "func_shelf_impact", true, 1);
FadeGlobalSoundVolume(0.00f, 0.01f);
AddTimer("", 5.0f, "fix_volume");
SetEntityPlayerInteractCallback("leverarea_1", "func_leverpuzzle1", false);
SetEntityPlayerInteractCallback("leverarea_2", "func_leverpuzzle2", false);
SetEntityPlayerInteractCallback("leverarea_3", "func_leverpuzzle3", false);
SetEntityPlayerInteractCallback("leverarea_4", "func_leverpuzzle4", false);
SetEntityPlayerInteractCallback("leverarea_5", "func_leverpuzzle5", false);
SetEntityPlayerInteractCallback("leverarea_6", "func_leverpuzzle6", false);
SetLocalVarInt("leverpuzzle_var", 2);
SetLocalVarInt("levers_functional", 1);
SetLocalVarInt("lever1_state", 2);
SetLocalVarInt("lever2_state", 1);
SetLocalVarInt("lever3_state", 2);
SetLocalVarInt("lever4_state", 2);
SetLocalVarInt("lever5_state", 2);
SetLocalVarInt("lever6_state", 1);
}
//This is where I add in callbacks for the script, blahblah
//main script below.
void func_leverpuzzle1(string &in asEntity)
{
if(GetLocalVarInt("levers_functional") == 0)
{

}
else if(GetLocalVarInt("levers_functional") == 1)
{
if(GetLocalVarInt("leverpuzzle_var") < 6)
{
PlayGuiSound("lock_door.snt", 1.0f);
switch(GetLocalVarInt("lever1_state"))
{
case 1:
SetLocalVarInt("lever1_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever1_up", true);
SetEntityActive("lever1_down", false);
break;
case 2:
SetLocalVarInt("lever1_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever1_down", true);
SetEntityActive("lever1_up", false);
break;
}
switch(GetLocalVarInt("lever3_state"))
{
case 1:
SetLocalVarInt("lever3_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever3_up", true);
SetEntityActive("lever3_down", false);
break;
case 2:
SetLocalVarInt("lever3_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever3_down", true);
SetEntityActive("lever3_up", false);
break;
}
switch(GetLocalVarInt("lever1_state"))
{
case 1:
SetLocalVarInt("lever5_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever5_up", true);
SetEntityActive("lever5_down", false);
break;
case 2:
SetLocalVarInt("lever5_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever5_down", true);
SetEntityActive("lever5_up", false);
break;

}
}
}
}
///////////
void func_leverpuzzle2(string &in asEntity)
{
if(GetLocalVarInt("levers_functional") == 0)
{

}
else if(GetLocalVarInt("levers_functional") == 1)
{
if(GetLocalVarInt("leverpuzzle_var") < 6)
{
PlayGuiSound("lock_door.snt", 1.0f);
switch(GetLocalVarInt("lever2_state"))
{
case 1:
SetLocalVarInt("lever2_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever2_up", true);
SetEntityActive("lever2_down", false);
break;
case 2:
SetLocalVarInt("lever2_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever2_down", true);
SetEntityActive("lever2_up", false);
break;
}
switch(GetLocalVarInt("lever3_state"))
{
case 1:
SetLocalVarInt("lever3_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever3_up", true);
SetEntityActive("lever3_down", false);
break;
case 2:
SetLocalVarInt("lever3_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever3_down", true);
SetEntityActive("lever3_up", false);
break;
}
switch(GetLocalVarInt("lever6_state"))
{
case 1:
SetLocalVarInt("lever6_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever6_up", true);
SetEntityActive("lever6_down", false);
break;
case 2:
SetLocalVarInt("lever6_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever6_down", true);
SetEntityActive("lever6_up", false);
break;
}
}
}
}
/////////
void func_leverpuzzle3(string &in asEntity)
{
if(GetLocalVarInt("levers_functional") == 0)
{

}
else if(GetLocalVarInt("levers_functional") == 1)
{
if(GetLocalVarInt("leverpuzzle_var") < 6)
{
PlayGuiSound("lock_door.snt", 1.0f);
switch(GetLocalVarInt("lever3_state"))
{
case 1:
SetLocalVarInt("lever3_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever3_up", true);
SetEntityActive("lever3_down", false);
break;
case 2:
SetLocalVarInt("lever3_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever3_down", true);
SetEntityActive("lever3_up", false);
break;
}
switch(GetLocalVarInt("lever4_state"))
{
case 1:
SetLocalVarInt("lever4_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever4_up", true);
SetEntityActive("lever4_down", false);
break;
case 2:
SetLocalVarInt("lever4_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever4_down", true);
SetEntityActive("lever4_up", false);
break;
}
switch(GetLocalVarInt("lever6_state"))
{
case 1:
SetLocalVarInt("lever6_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever6_up", true);
SetEntityActive("lever6_down", false);
break;
case 2:
SetLocalVarInt("lever6_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever6_down", true);
SetEntityActive("lever6_up", false);
break;
}
}
}
}
//////////////
void func_leverpuzzle4(string &in asEntity)
{
if(GetLocalVarInt("levers_functional") == 0)
{

}
else if(GetLocalVarInt("levers_functional") == 1)
{
if(GetLocalVarInt("leverpuzzle_var") < 6)
{
PlayGuiSound("lock_door.snt", 1.0f);
switch(GetLocalVarInt("lever4_state"))
{
case 1:
SetLocalVarInt("lever4_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever4_up", true);
SetEntityActive("lever4_down", false);
break;
case 2:
SetLocalVarInt("lever4_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever4_down", true);
SetEntityActive("lever4_up", false);
break;
}
switch(GetLocalVarInt("lever1_state"))
{
case 1:
SetLocalVarInt("lever1_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever1_up", true);
SetEntityActive("lever1_down", false);
break;
case 2:
SetLocalVarInt("lever1_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever1_down", true);
SetEntityActive("lever1_up", false);
break;
}
switch(GetLocalVarInt("lever2_state"))
{
case 1:
SetLocalVarInt("lever2_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever2_up", true);
SetEntityActive("lever2_down", false);
break;
case 2:
SetLocalVarInt("lever2_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever2_down", true);
SetEntityActive("lever2_up", false);
break;
}
}
}
}
////////////
void func_leverpuzzle5(string &in asEntity)
{
if(GetLocalVarInt("levers_functional") == 0)
{

}
else if(GetLocalVarInt("levers_functional") == 1)
{
if(GetLocalVarInt("leverpuzzle_var") < 6)
{
PlayGuiSound("lock_door.snt", 1.0f);
switch(GetLocalVarInt("lever5_state"))
{
case 1:
SetLocalVarInt("lever5_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever5_up", true);
SetEntityActive("lever5_down", false);
break;
case 2:
SetLocalVarInt("lever5_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever5_down", true);
SetEntityActive("lever5_up", false);
break;
}
switch(GetLocalVarInt("lever2_state"))
{
case 1:
SetLocalVarInt("lever2_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever2_up", true);
SetEntityActive("lever2_down", false);
break;
case 2:
SetLocalVarInt("lever2_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever2_down", true);
SetEntityActive("lever2_up", false);
break;
}
}
}
}
//////////
void func_leverpuzzle6(string &in asEntity)
{
if(GetLocalVarInt("levers_functional") == 0)
{

}
else if(GetLocalVarInt("levers_functional") == 1)
{
if(GetLocalVarInt("leverpuzzle_var") < 6)
{
PlayGuiSound("lock_door.snt", 1.0f);
switch(GetLocalVarInt("lever6_state"))
{
case 1:
SetLocalVarInt("lever6_state", 2);
AddLocalVarInt("leverpuzzle_var", -1);
SetEntityActive("lever6_up", true);
SetEntityActive("lever6_down", false);
break;
case 2:
SetLocalVarInt("lever6_state", 1);
AddLocalVarInt("leverpuzzle_var", 1);
SetEntityActive("lever6_down", true);
SetEntityActive("lever6_up", false);
break;
}
}
}
}
/////////////

The puzzle involves pressing levers into their slots, which will toggle the position of certain other levers. When they're all pushed down, the variable "leverpuzzle_var" should equal 6 (for 6 switches pressed.) However, theres either an error in control flow or with the variable, as I can still toggle the levers after I push all 6 in.
Anyone see the problem here?
Oh, and the if "levers_functional" is for another part I'm adding later, but for now its set to be true (aka '1') as default, so Ignore that.

Oh, and secondly. When theyre all pushed in I want to have another function run. What is the best way of doing that?

THANKS
(This post was last modified: 07-28-2014, 04:33 AM by Vale.)
07-27-2014, 02:07 AM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#2
RE: Puzzle Script Problem?

Humm. Checking...

I think you should monitor the value of levers_functional
AddDebugMessage( "leverpuzzle_var("+leverpuzzle_var+")", false);
Those levers may be increasing the value of that variable several times cause you're using SetEntityPlayerInteractCallback to trigger the function instead of a callback that detects only when the state changes.
If I'm correct, you should see that variable getting too big by the time you finished the puzzle, so it's always > than 6 and the code keeps on.

(This post was last modified: 07-27-2014, 04:45 AM by Daemian.)
07-27-2014, 04:24 AM
Find
Vale Offline
Member

Posts: 92
Threads: 13
Joined: Mar 2014
Reputation: 7
#3
RE: Puzzle Script Problem?

Mmm. You misunderstood, and I underdescribed. It uses examine areas for interaction to toggle their states, because they aren't quite... levers. However, I will take your advice and monitor the value of the variable. Thanks for your time.
07-27-2014, 05:09 AM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#4
RE: Puzzle Script Problem?

Oh. Ok. Yeah you should still check what's happening with that var.
Can't you disable a lever area after the player was done with it? Or you need it for later?

07-27-2014, 05:29 AM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#5
RE: Puzzle Script Problem?

(07-27-2014, 05:09 AM)valetheimpaler Wrote: Mmm. You misunderstood, and I underdescribed. It uses examine areas for interaction to toggle their states, because they aren't quite... levers. However, I will take your advice and monitor the value of the variable. Thanks for your time.
You could just deactivate the examine area when you're done...

(07-27-2014, 02:07 AM)valetheimpaler Wrote: Oh, and secondly. When they're all pushed in I want to have another function run. What is the best way of doing that?

Call a new function. Name the function whatever you want and then after that put (); (refer to first code below). After that your function is basically done. For the callback, use the same function line but don't use the semi colon (refer to second code below). Below is an example (refer to last code).

Spoiler below!

FIRST
PHP Code: (Select All)
FUNCTIONNAME(); 

SECOND
PHP Code: (Select All)
void FUNCTIONNAME()
{
///whatever you want to do here let it be spawning a monster or a dildo


THIRD
PHP Code: (Select All)
void OnStart()
{
ExecCustFunc();
}

void ExecCustFunc()
{
//Execute shit!



"Veni, vidi, vici."
"I came, I saw, I conquered."
(This post was last modified: 07-27-2014, 06:28 AM by PutraenusAlivius.)
07-27-2014, 06:27 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#6
RE: Puzzle Script Problem?

A script as big as that would be much easier to read if it was properly indented and formatted. Perhaps provide a http://www.pastebin.com link?

(This post was last modified: 07-27-2014, 07:22 PM by Mudbill.)
07-27-2014, 06:29 AM
Find
Vale Offline
Member

Posts: 92
Threads: 13
Joined: Mar 2014
Reputation: 7
#7
RE: Puzzle Script Problem?

Alright first captain, that answers my second question. Thank you.
http://pastebin.com/SFP0z0Hx
There's a link to the code.
And I'll post a video so you can understand what the puzzle is exactly.

holy jeezus, I figured it out. Theres one tiny error in my code, which originates from me copying and pasting that switch piece and inputting new numbers for each.
Look at the switch after line 65 in the pastebin and you can probably see whats wrong.
When I was trying to get a video of the puzzle I managed to get it to stop while one lever was still up, so I figured that there was an error along those lines.
Thanks again, and sorry for the trouble!
(This post was last modified: 07-27-2014, 02:15 PM by Vale.)
07-27-2014, 02:05 PM
Find




Users browsing this thread: 1 Guest(s)