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

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 a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: [ZScript] 'Weapon' class, 'invoker' is also 'self'(?)

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

by Fishytza » Sat Nov 12, 2016 8:50 am

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.

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

by Graf Zahl » Sat Nov 12, 2016 7:46 am

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.

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

by Major Cooke » Fri Nov 11, 2016 7:03 pm

No. I looked into the code. But I'm not a very good at interpreting some things.

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

by Fishytza » Fri Nov 11, 2016 6:47 pm

So you were making it up? -_-

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

by Major Cooke » Fri Nov 11, 2016 6:45 pm

It was mostly speculation to begin with after browsing the code. :mrgreen:

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

by Fishytza » Fri Nov 11, 2016 6:42 pm

Well, honestly I rather have Graf confirm this.

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

by Major Cooke » Fri Nov 11, 2016 6:40 pm

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.

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

by Fishytza » Fri Nov 11, 2016 6:17 pm

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'.

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

by Major Cooke » Fri Nov 11, 2016 6:08 pm

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)

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

by Fishytza » Fri Nov 11, 2016 6:05 pm

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?

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

by Major Cooke » Fri Nov 11, 2016 6:01 pm

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.

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

by Fishytza » Fri Nov 11, 2016 5:53 pm

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.

Top