Khorus Posted November 6, 2012 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."); } 0 Share this post Link to post
Gez Posted November 6, 2012 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. 0 Share this post Link to post
Khorus Posted November 6, 2012 @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? 0 Share this post Link to post
Gez Posted November 6, 2012 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. 0 Share this post Link to post
Khorus Posted November 6, 2012 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. :) 0 Share this post Link to post
Gez Posted November 6, 2012 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. 0 Share this post Link to post
Khorus Posted November 6, 2012 That worked perfectly, thanks again. :) 0 Share this post Link to post