Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Khorus

ACS help: LockedExecute

Recommended Posts

Hello helpful programmer genius types,

I want a switch to lower a floor while requiring the Oracle Key to do so. The script compiler complains that the "else" line in the following code is an invalid statement. I'm completely hopeless when it comes to anything code related, so any help here would be wunderbar! :D

script 5 (void)

{
    ACS_LockedExecute(6,0,6,0,15);
}

script 6 (void)
{
    if (CheckInventory("OracleKey"))
        Print(s:"The way is open.");
        {
            Floor_LowerToLowest(15,14);
        }
    else
        Print(s:"You require the Oracle Key.");
}

Share this post


Link to post
Khorus said:

Hello helpful programmer genius types,

I want a switch to lower a floor while requiring the Oracle Key to do so. The script compiler complains that the "else" line in the following code is an invalid statement. I'm completely hopeless when it comes to anything code related, so any help here would be wunderbar! :D

script 5 (void)

{
    ACS_LockedExecute(6,0,6,0,15);
}

script 6 (void)
{
    if (CheckInventory("OracleKey"))
        Print(s:"The way is open.");
        {
            Floor_LowerToLowest(15,14);
        }
    else
        Print(s:"You require the Oracle Key.");
}


Your "Print(s:"The way is open.");" is not in the curly-brace block. Therefore, it is the only thing executed conditionally. The block that comes after (with Floor_LowerToLowest()) is executed inconditionally, so it would always happen. It's "detached" from the if.

When you arrive at the else, it is no longer connected to the if, so it invalid.

The fix is simply to move the Print line inside the block.

Share this post


Link to post

@Gez: Heeey, that worked just great! Much props! :D

One issue is that the switch is animating and playing the activation noise despite the player not having the key on them. Can anything be done about that?

Share this post


Link to post

What special does your switch linedef have?

From what I understand, you have script 5 that calls script 6 to run if the player has the Order key (key type 15).

If the script runs, there's no reason for the animation not to play.

Share this post


Link to post
Gez said:

What special does your switch linedef have?

From what I understand, you have script 5 that calls script 6 to run if the player has the Order key (key type 15).

If the script runs, there's no reason for the animation not to play.


Action 80 "Script Execute". So the line action is triggered regardless if the player has the key or not. Not a huge deal, I can explain it away in the "key required" message.

Yes, that's correct. :)

Share this post


Link to post

Something you can do if you want the switch not to animate if the player does not have the key: use special 84:ACS_ExecuteWithResult. Then, in the script that is directly run by the linedef (so, script 5), have this:

    if (!(CheckInventory("OracleKey")))
    {
        SetResultValue(0);
    }
So the script will be considered to have failed if the player does not have the key.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×