Page 1 of 1

[DECORATE] Problem with dummy inventory

PostPosted: Sat Jul 31, 2021 12:08 am
by Baysha
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?

Re: [DECORATE] Problem with dummy inventory

PostPosted: Sat Jul 31, 2021 5:25 am
by Logan MTM
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
   }
}

Re: [DECORATE] Problem with dummy inventory

PostPosted: Sat Jul 31, 2021 5:29 am
by Jarewill
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

Re: [DECORATE] Problem with dummy inventory

PostPosted: Sat Jul 31, 2021 1:57 pm
by Baysha
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.