A_TakeInventory does not function properly in zscript

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
insightguy
Posts: 1730
Joined: Tue Mar 22, 2011 11:54 pm

A_TakeInventory does not function properly in zscript

Post by insightguy »

Code: Select all

override bool used(Actor user)
	{
		holdCounter++;
		A_GiveInventory ("WeaponInstall" , 1 , AAPTR_PLAYER1);
		if(holdCounter >= 100)
		{
			A_TakeInventory ("WeaponInstall" , 100 , AAPTR_PLAYER1);
			Super.touch(user);
		}
		if (user.player) { user.player.usedown = false; } 
		return true;
	}
A_TakeInventory ("WeaponInstall" , 100 , AAPTR_PLAYER1); does not take away the player's "WeaponInstall" but A_GiveInventory ("WeaponInstall" , 1 , AAPTR_PLAYER1); works perfectly fine. Is this supposed to be normal behavior?

COPY OF THE PROJECT
User avatar
phantombeta
Posts: 2089
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: A_TakeInventory does not function properly in zscript

Post by phantombeta »

You're calling the function incorrectly. In non-action scopes the self pointer points to the real actor.
You need to use "Owner.A_TakeInventory ("WeaponInstall" , 100 , AAPTR_PLAYER1)" instead. A_GiveInventory works without that only because of the way the inventory is stored.
User avatar
insightguy
Posts: 1730
Joined: Tue Mar 22, 2011 11:54 pm

Re: A_TakeInventory does not function properly in zscript

Post by insightguy »

phantombeta wrote:You're calling the function incorrectly. In non-action scopes the self pointer points to the real actor.
You need to use "Owner.A_TakeInventory ("WeaponInstall" , 100 , AAPTR_PLAYER1)" instead. A_GiveInventory works without that only because of the way the inventory is stored.
Thank you! This fixed it.

@Mods, how do I lock this or move this away?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49071
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: A_TakeInventory does not function properly in zscript

Post by Graf Zahl »

phantombeta wrote:A_GiveInventory works without that only because of the way the inventory is stored.
It actually doesn't really 'work' because it gives the item the wrong owner which also could lead to unexpected behavior. This call should also be fixed.

This is one of those sloppy implementation details from old times which I unfortunately did not catch in time before making a release. But I think it's a good idea to let A_GiveInventory print a warning message, if it gets called on an owned inventory item. Remember: This is not defined behavior but merely a side effect of how the inventory chain is linked. So it's prone to getting broken, if stuff changes.
User avatar
phantombeta
Posts: 2089
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: A_TakeInventory does not function properly in zscript

Post by phantombeta »

That's what I meant by "only because of the way the inventory is stored."
(I should probably have mentioned it's undefined behaviour, of course, since non-programmers probably won't realize that such a thing is undefined behaviour and a side effect of the specific implementation.)
Post Reply

Return to “Closed Bugs [GZDoom]”