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
Let's play "why doesn't my script work?"!
Streetboat Offline
Posting Freak

Posts: 1,099
Threads: 40
Joined: Mar 2011
Reputation: 56
#1
Let's play "why doesn't my script work?"!

Okay, so here's the scenario. Four valves (each starting at the middle position) turn in a specific order to open a portcullis. The correct order goes as such: R R L R. If the player gets one wrong, steam spurts out of a pipe and the order resets. Seems simple enough, right? Right. Here's the code.

void valve1turn(string &in asEntity, int alState)
{
if(alState == 1)
    {
    AddLocalVarInt("gateopen", 1);
    if(GetLocalVarInt("gateopen") == 4)
        {
        SetMoveObjectState("castle_portcullis_1", 0.7);
        }
    else
        {
        AddLocalVarInt("gateopen", 1);
        }
    }
if(alState == 0)
    {
    SetMoveObjectState("castle_portcullis_1", 0);
    PlaySoundAtEntity("", "13_press_done.snt", "steamarea", 0, false);
    CreateParticleSystemAtEntity("", "ps_steam_puff.ps", "steamarea", false);
    SetLocalVarInt("gateopen", 0);
    for(int i=1;i<=4;i++)SetWheelAngle("valvepuzzle_"+i, 0, true);
    }
}
void valve2turn(string &in asEntity, int alState)
{
if(alState == 1)
    {
    AddLocalVarInt("gateopen", 1);
    if(GetLocalVarInt("gateopen") == 4)
        {
        SetMoveObjectState("castle_portcullis_1", 0.7);
        }
    else
        {
        AddLocalVarInt("gateopen", 1);
        }
    }
if(alState == 0)
    {
    SetMoveObjectState("castle_portcullis_1", 0);
    PlaySoundAtEntity("", "13_press_done.snt", "steamarea", 0, false);
    CreateParticleSystemAtEntity("", "ps_steam_puff.ps", "steamarea", false);
    SetLocalVarInt("gateopen", 0);
    for(int i=1;i<=4;i++)SetWheelAngle("valvepuzzle_"+i, 0, true);
    }
}
void valve3turn(string &in asEntity, int alState)
{
if(alState == 0)
    {
    AddLocalVarInt("gateopen", 1);
    if(GetLocalVarInt("gateopen") == 4)
        {
        SetMoveObjectState("castle_portcullis_1", 0.7);
        }
    else
        {
        AddLocalVarInt("gateopen", 1);
        }
    }
if(alState == 1)
    {
    SetMoveObjectState("castle_portcullis_1", 0);
    PlaySoundAtEntity("", "13_press_done.snt", "steamarea", 0, false);
    CreateParticleSystemAtEntity("", "ps_steam_puff.ps", "steamarea", false);
    SetLocalVarInt("gateopen", 0);
    for(int i=1;i<=4;i++)SetWheelAngle("valvepuzzle_"+i, 0, true);
    }
}
void valve4turn(string &in asEntity, int alState)
{
if(alState == 1)
    {
    AddLocalVarInt("gateopen", 1);
    if(GetLocalVarInt("gateopen") == 4)
        {
        SetMoveObjectState("castle_portcullis_1", 0.7);
        }
    else
        {
        AddLocalVarInt("gateopen", 1);
        }
    }
if(alState == 0)
    {
    SetMoveObjectState("castle_portcullis_1", 0);
    PlaySoundAtEntity("", "13_press_done.snt", "steamarea", 0, false);
    CreateParticleSystemAtEntity("", "ps_steam_puff.ps", "steamarea", false);
    SetLocalVarInt("gateopen", 0);
    for(int i=1;i<=4;i++)SetWheelAngle("valvepuzzle_"+i, 0, true);
    }
}

Here's where it sucks. If I input the correct order, nothing happens. The portcullis is still stuck there. If I move any of the wheels other than the third to any position, nothing happens. Left or right, wheels 1, 2, and 4 do nothing. Wheel 3 acts as it should; right (the wrong direction) does the steam thing and resets the wheels, and left clicks as it should.

So, what do? Why won't this work? I feel like my logic is fairly sound withing the coding. It's late, and I don't want to work on this any more, so I was hoping someone more experienced had some insight. Smile

[Image: signature-2.png]
(This post was last modified: 04-13-2013, 04:47 AM by Streetboat.)
04-12-2013, 06:05 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: Let's play "why doesn't my script work?"!

Assuming the wheels function similarly to the levers and the wheel that you turn to work the burner near the end of the main game, wouldn't script calculate it as the wheel end positions being at -1 and 1?
And if not that, then maybe similar to the cogwheel levers in the sewer? They end at 0 and 2.

What you could also do is add Debug Messages in the coding of your 1st, 2nd and 4th wheels. You may through this be able to determine exactly where your code is going wrong.

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 04-12-2013, 06:30 AM by Romulator.)
04-12-2013, 06:27 AM
Find
Streetboat Offline
Posting Freak

Posts: 1,099
Threads: 40
Joined: Mar 2011
Reputation: 56
#3
RE: Let's play "why doesn't my script work?"!

Ha, I'm an idiot. You're absolutely right, the problem was that they started at 0 and ended at 1. I blame the fact that I was tired. Tongue

However, the issue still remains that when I do it all right, the door doesn't move at all. I'm certain it's a moveobject, I've used it before...

[Image: signature-2.png]
04-12-2013, 08:17 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
RE: Let's play "why doesn't my script work?"!

Why do you have three functions that do exactly the same thing?

Tutorials: From Noob to Pro
(This post was last modified: 04-12-2013, 08:35 AM by Your Computer.)
04-12-2013, 08:30 AM
Website Find
Streetboat Offline
Posting Freak

Posts: 1,099
Threads: 40
Joined: Mar 2011
Reputation: 56
#5
RE: Let's play "why doesn't my script work?"!

Where?

There are four valves, and each function pertains to a different valve. What do you mean?

[Image: signature-2.png]
04-12-2013, 08:52 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
RE: Let's play "why doesn't my script work?"!

valve1turn, valve2turn and valve4turn do the exact same thing (valve3turn only differs in the state checks). The issue, however, that i can spot is that you're adding to the local map variable more times than you should. Turn one valve correctly, the local map variable becomes 2 by the time the function ends. Turn the second valve correctly, it adds up to 3, notices that it doesn't equal 4 and then moves on to the else, adding up to 4. Turn the third valve correctly, the local map variable adds up to 5, and so on. Therefore, even though the variable reaches 4 at some point, it is never at 4 when checked for 4; it is either greater than or less than 4 at the time it is checked.

Tutorials: From Noob to Pro
(This post was last modified: 04-12-2013, 09:10 AM by Your Computer.)
04-12-2013, 09:08 AM
Website Find
Streetboat Offline
Posting Freak

Posts: 1,099
Threads: 40
Joined: Mar 2011
Reputation: 56
#7
RE: Let's play "why doesn't my script work?"!

Thank you. I will look into that tomorrow. Smile

[Image: signature-2.png]
04-12-2013, 09:22 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#8
RE: Let's play "why doesn't my script work?"!

It always takes me so long to reply. You can read this if you want, but I'm sure you would have the general idea already

There are two ways I believe you could fix this from past experience... (I'm a nooby scripter Tongue)
1. Make the door explode Tongue The downside is it is noisy and if done incorrectly, can be a bit messy and a downside, but it clears the path. You would do this with
SetPropHealth("<portcullis>", 0.0f);
2. Use force:Well, the first thing you have to do is make sure the door unlocks after all the conditions are met. I don't know exactly where that code is in your code because I cannot read it specifically coz of my script knowlege, then maybe apply force that pushes the door open from either in front or behind.
SetSwingDoorLocked("<portcullis>", false, true);
SetSwingDoorDisableAutoClose("<portcullis>", true);  
SetSwingDoorClosed("<portcullis>", false, true);
AddPropForce("<portcullis>", x, y, z, "world");
The first line unlocks the door. The next one makes sure that when force is applied, the door doesn't just shut itself again. The next code opens the door ever so slightly, and then the AddPropForce simply pushes the door open Smile
Change:
"<Portcullis>" - Change to the name of your door as indicated in your Level Editor.
x, y, z, - Change to the needed co-ordinate. Your door should open either along the x or z axis :)

I may not be the best but that MAY help or give you an insight as to what to do Smile

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 04-12-2013, 09:27 AM by Romulator.)
04-12-2013, 09:26 AM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#9
RE: Let's play "why doesn't my script work?"!

(04-12-2013, 09:08 AM)Your Computer Wrote: valve1turn, valve2turn and valve4turn do the exact same thing (valve3turn only differs in the state checks). The issue, however, that i can spot is that you're adding to the local map variable more times than you should. Turn one valve correctly, the local map variable becomes 2 by the time the function ends. Turn the second valve correctly, it adds up to 3, notices that it doesn't equal 4 and then moves on to the else, adding up to 4. Turn the third valve correctly, the local map variable adds up to 5, and so on. Therefore, even though the variable reaches 4 at some point, it is never at 4 when checked for 4; it is either greater than or less than 4 at the time it is checked.

Oh yeah. So it should be changed to
PHP Code: (Select All)
if(GetLocalVarInt("gateopen") >= 4
Since it's larger than 4. Unless it's somehow 4 (MAGIC), i added an 4 so it became "larger than/equal to" 4.

"Veni, vidi, vici."
"I came, I saw, I conquered."
(This post was last modified: 04-12-2013, 10:06 AM by PutraenusAlivius.)
04-12-2013, 10:05 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#10
RE: Let's play "why doesn't my script work?"!

As long as the outcome does not reach an integer >= 4 before all four valves are turned to the correct position, it should work fine Smile

Discord: Romulator#0001
[Image: 3f6f01a904.png]
04-12-2013, 03:30 PM
Find




Users browsing this thread: 5 Guest(s)