[DECORATE] Problem with dummy inventory

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

[DECORATE] Problem with dummy inventory

Postby Baysha » Sat Jul 31, 2021 12:08 am

Hello. I've run into a problem with using dummy inventory items and A_TakeInventory to simulate variables in DECORATE. My code is as follows:

Code: Select allExpand view
Actor CoinGiver : Inventory
{

}

Actor SmallCoins
{
   States
   {
      Spawn:
      TNT1 A 0
      TNT1 A 0 A_GiveInventory("CoinGiver",random(1,3))
      Coins:
      TNT1 A 0
      TNT1 A 1 A_DropItem("SilverCoin")
      TNT1 A 0 A_TakeInventory("CoinGiver",1)
      TNT1 A 0 A_JumpIfInventory("CoinGiver",0,"StopCoins")
      Loop
      StopCoins:
      TNT1 A 0
      Stop
   }
}


Now this is intended to drop a random amount of coins between 1 and 3. However, when I run it, it just spawns coins endlessly. Further more, the "forgetful imp" (The example used for this page: https://zdoom.org/wiki/A_TakeInventory ) on the ZDoom wiki doesn't work for me. So this seems to suggest the problem is with the dummy inventory. Can anyone help me with this?
User avatar
Baysha
 
Joined: 24 Feb 2018

Re: [DECORATE] Problem with dummy inventory

Postby Logan MTM » Sat Jul 31, 2021 5:25 am

Try with CountInv:

Code: Select allExpand view
Actor CoinGiver : Inventor

Actor SmallCoins
{
   States
   {
      Spawn:
      TNT1 A 0
      TNT1 A 0 A_GiveInventory("CoinGiver",random(1,3))
      Coins:
      TNT1 A 0
      TNT1 A 1 A_DropItem("SilverCoin")
      TNT1 A 0 A_TakeInventory("CoinGiver",1)
      TNT1 A 0
        {
        If(countinv("CoinGiver")) { return state("coins");  } Else { return state(""); }
        }
     
      TNT1 A 0
      Stop
   }
}
Last edited by Logan MTM on Sat Jul 31, 2021 5:39 am, edited 2 times in total.
User avatar
Logan MTM
I can see you...
 
Joined: 16 Jan 2006
Location: Rio de Janeiro - Brazil

Re: [DECORATE] Problem with dummy inventory

Postby Jarewill » Sat Jul 31, 2021 5:29 am

First issue is that you don't specify MaxAmount of the CoinGiver item, meaning it's maximum amount is 1.
The second issue is checking for 0 in A_JumpIfInventory is treated as max amount, causing an infinite loop.
Try changing it to either what Logan posted or this:
Code: Select allExpand view
      TNT1 A 0 A_JumpIfInventory("CoinGiver",1,1)
      Goto 
StopCoins
      TNT1 A 0 
//Jump here if the actor still has the item in inventory
      
Loop
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: [DECORATE] Problem with dummy inventory

Postby Baysha » Sat Jul 31, 2021 1:57 pm

Jarewill wrote:First issue is that you don't specify MaxAmount of the CoinGiver item, meaning it's maximum amount is 1.
The second issue is checking for 0 in A_JumpIfInventory is treated as max amount, causing an infinite loop.
Try changing it to either what Logan posted or this:
Code: Select allExpand view
      TNT1 A 0 A_JumpIfInventory("CoinGiver",1,1)
      Goto StopCoins
      TNT1 A 0 
//Jump here if the actor still has the item in inventory
      Loop

That fixed it. Thank you.
User avatar
Baysha
 
Joined: 24 Feb 2018


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests