[ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
User avatar
Fishytza
Posts: 792
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

[ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Fishytza »

It seems that for weapons invoker is the same as the player who wields the weapon.

Code: Select all

Class WTest : Shotgun
{
	States
	{
	Fire:
		SHTG B 20
		{
			invoker.A_GiveInventory("Cell", 6);
			A_LogInt(invoker.CountInv("Cell"));
			A_LogInt(CountInv("Cell"));
		}
		Goto Ready;
	}
}
Type "give WTest" then "use WTest" in the console to select this and try to fire it.

If you have the standard Doom HUD, you should see your ammo counters.
As you can see from the Cell ammo counter it's you who receives the 6 Cells.
The two A_LogInt calls confirm this because they print the same result.
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Major Cooke »

Invoker is mainly designed with the ability to modify its properties and store variables of its own, last I checked. Meaning they cannot store inventory of their own and will thus give it to the player instead.

Correct me if I'm wrong, Graf.
User avatar
Fishytza
Posts: 792
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Fishytza »

Ok. But what doesn't make sense here is why does invoker.CountInv() show self's inventory? invoker.CountInv() seems to work correctly with CustomInventory so why not with Weapon?

In this case, if A_GiveInventory gives directly to the player then shouldn't A_LogInt(invoker.CountInv) print 0?
Last edited by Fishytza on Fri Nov 11, 2016 6:10 pm, edited 2 times in total.
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Major Cooke »

Inventory itself is capable of having inventory, thanks to Edward850 adding the +INVENTORY.TRANSFER flag. What he did not do is manipulate weapons when he made it. So invoker is most likely not so limited as weapons are.

Also you called invoker.A_GiveInventory (assuming you did the exact same test on a custominventory actor instead of a weapon), so no, the countinv wouldn't be 0. Invoker means checking the custominventory's inventory. Not the player's.

Again, I don't think weapons were ever designed to have inventory like actual inventory can. It's two whole different actors. ZDoom was introduced to +INVENTORY.TRANSFER and thus inventory is capable of storing inventory within itself -- and giving that inventory to other actors upon pickup. (Inventoryception much? :P)
User avatar
Fishytza
Posts: 792
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Fishytza »

Spoiler: stuff that doesn't matter anymore
EDIT:

Code: Select all

Class CInvTest : CustomInventory
{
   States
   {
   Pickup:
      TNT1 A 0
      {
         invoker.A_GiveInventory("Cell", 6);
         A_LogInt(invoker.CountInv("Cell"));
         A_LogInt(CountInv("Cell"));
      }
      Stop;
   }
}
Guess what, the first A_LogInt prints 6, the second prints 0. The player doesn't get the 6 Cells.
'CustomInventory' works. This is definitely a bug with 'Weapon'.
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Major Cooke »

That's what I was saying, except as far as I can tell, it was supposed to be this way, not a bug. Weapons, while held, point towards the player instead of itself for certain functions like inventory.
User avatar
Fishytza
Posts: 792
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Fishytza »

Well, honestly I rather have Graf confirm this.
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Major Cooke »

It was mostly speculation to begin with after browsing the code. :mrgreen:
User avatar
Fishytza
Posts: 792
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Fishytza »

So you were making it up? -_-
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Major Cooke »

No. I looked into the code. But I'm not a very good at interpreting some things.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49230
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Graf Zahl »

Ha, ha. You ran into one of ZDoom's implementation oddities here. An owned inventory item cannot own any other items, it uses its Inventory pointer to link the player's inventory together. So by giving something to the owned weapon it automatically got appended to the player's inventory. This is something that cannot really be fixed. I think I just let A_GiveInventory for owned items fail because it makes no sense.
User avatar
Fishytza
Posts: 792
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

Post by Fishytza »

Now it makes sense. Owned items cannot have their own inventory. I just did a quick test with CustomInventory's 'Use' state and, predictably enough, it behaved the same way as with weapons.
Post Reply

Return to “Closed Bugs [GZDoom]”