VoidEater Posted December 18, 2021 I'm trying to write an ACS script that runs a WHILE loop checking as to whether the sanity inventory item is less than or equal to 0, and if it is, to then kill the player. Here are two different versions of the script I've tried: While("Sanity_Pickup" <= 0) { Thing_Damage(1, 5000, MOD_UNKNOWN); } While("Sanity_Pickup" >= 0) { if(CheckInventory("Sanity_Pickup") <= 0) Thing_Damage(1, 5000, MOD_UNKNOWN); } I know that neither of them should work just based off of the fact I'm using a WHILE loop but I'm at a bit of a loss on what to replace it with honestly. 0 Quote Share this post Link to post
boris Posted December 18, 2021 You probably want something like while(CheckInventory("Sanity_Pickup") > 0) Delay(35); Thing_Damage(1, 0xffff, MOD_UNKNOWN); A couple things to note: - in your script you're comparing a string to an int. That doesn't work (in the way you might expect) - if you have potentially infinite loops you need to add a Delay, otherwise the script will be aborted (you'll get something like "Runaway script terminated" in the console) - keep in mind that assigning a TID to the player start does not work, you have to assign TIDs to the player through a script, see https://zdoom.org/wiki/Assigning_TIDs_to_Players 0 Quote Share this post Link to post
VoidEater Posted December 18, 2021 9 minutes ago, boris said: You probably want something like while(CheckInventory("Sanity_Pickup") > 0) Delay(35); Thing_Damage(1, 0xffff, MOD_UNKNOWN); A couple things to note: - in your script you're comparing a string to an int. That doesn't work (in the way you might expect) - if you have potentially infinite loops you need to add a Delay, otherwise the script will be aborted (you'll get something like "Runaway script terminated" in the console) - keep in mind that assigning a TID to the player start does not work, you have to assign TIDs to the player through a script, see https://zdoom.org/wiki/Assigning_TIDs_to_Players That makes a lot of sense. I copied your script and played around with it a bit but nothing seemed to be working. Ended up bringing the IF statement back into the script you proivided and boom, it worked. Looks like this now: Spoiler #include "zcommon.acs" script 1 ENTER { if(CheckInventory("Sanity_Pickup") == 0) GiveInventory("Sanity_Pickup", 100); //Player will always start with 100 Sanity if they open the map with 0 Thing_ChangeTID(0, 1 + PlayerNumber()); // This assigns a TID of 1 to the player //Play will die upon reaching 0 or less sanity. while(CheckInventory("Sanity_Pickup") > 0) Delay(1); if(CheckInventory("Sanity_Pickup") <= 0) Thing_Damage(1, 0xffff, MOD_UNKNOWN); } Thanks a bunch for the help man! 0 Quote Share this post Link to post
boris Posted December 18, 2021 6 minutes ago, OFFICIALDOOMGUY said: Ended up bringing the IF statement back into the script you proivided and boom, it worked. That doesn't makes sense. Think about it, you'll stay in the while loop as long as Sanity_Pickup is bigger than 0. So for the while loop to end Sanity_Pickup has to be smaller or equal to zero. Then checking for it being smaller or equal to zero will always be true. 0 Quote Share this post Link to post
VoidEater Posted December 18, 2021 (edited) 19 minutes ago, boris said: That doesn't makes sense. Think about it, you'll stay in the while loop as long as Sanity_Pickup is bigger than 0. So for the while loop to end Sanity_Pickup has to be smaller or equal to zero. Then checking for it being smaller or equal to zero will always be true. I don't know. I've tested it and as long as my sanity is anywhere between 1-100 then my character stays alive. If I then set it to 0 or have an item bring it below 0 my character dies. Here's a video showing it working. Edited December 18, 2021 by OFFICIALDOOMGUY added video link 1 Quote Share this post Link to post
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.