[ZScript] 'invoker' isn't recognized in named functions

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] 'invoker' isn't recognized in named functions

Post by Fishytza »

What it says in the title.

Trying to load this gives startup error: Unknown identifier 'invoker'. (Anonymous functions still recognize invoker.)

Code: Select all

Class CITest : CustomInventory
{
	States
	{
	Spawn:
		CLIP A -1 NoDelay A_GiveInventory("Clip", randompick(2,4,8,16));
		Stop;
	Pickup:
		TNT1 A 0 GiveIt;
		Stop;
	}

	void GiveIt() //Works fine as anonymous function
	{
		A_LogInt(invoker.CountInv("Clip"));
		A_SetInventory("Clip", invoker.CountInv("Clip"));
	}
}
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] 'invoker' isn't recognized in named functions

Post by Major Cooke »

I think that's limited to design. It will only work in an anonymous function.
User avatar
Fishytza
Posts: 792
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: [ZScript] 'invoker' isn't recognized in named functions

Post by Fishytza »

You're saying it's intentional? Well, I found a workaround anyway, but still

Code: Select all

Class CITest : CustomInventory
{
   States
   {
   Spawn:
      CLIP A -1 NoDelay A_GiveInventory("Clip", randompick(2,4,8,16));
      Stop;
   Pickup:
      TNT1 A 0 { GiveIt(invoker); }
      Stop;
   }

   void GiveIt(Actor ngaaah)
   {
      A_LogInt(ngaaah.CountInv("Clip"));
      A_SetInventory("Clip", ngaaah.CountInv("Clip"));
   }
}
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] 'invoker' isn't recognized in named functions

Post by Graf Zahl »

Major Cooke wrote:I think that's limited to design. It will only work in an anonymous function.
It will only work in ACTION functions. Anonymous functions are 'action' by default. Unfortunately this is necessary to prevent the whole system from falling apart. Regular functions without an 'action' qualifier only get a self pointer, but not the added information to determine from where they were called.
User avatar
Fishytza
Posts: 792
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: [ZScript] 'invoker' isn't recognized in named functions

Post by Fishytza »

Graf Zahl wrote:It will only work in ACTION functions. Anonymous functions are 'action' by default.
Thanks, Graf! All I had to do was put the 'action' word and now it works. :D

Code: Select all

   action void GiveIt()
   {
      A_LogInt(invoker.CountInv("Clip"));
      A_SetInventory("Clip", invoker.CountInv("Clip"));
   }
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] 'invoker' isn't recognized in named functions

Post by Major Cooke »

Graf Zahl wrote:It will only work in ACTION functions. Anonymous functions are 'action' by default. Unfortunately this is necessary to prevent the whole system from falling apart. Regular functions without an 'action' qualifier only get a self pointer, but not the added information to determine from where they were called.
So either anonymous functions or named functions with 'action'. I'll write that up on the wiki.
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] 'invoker' isn't recognized in named functions

Post by Graf Zahl »

Yes, but keep in mind that if you call a non-action function from an action function and then call another action function from the non-action function it won't have this info anymore.
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] 'invoker' isn't recognized in named functions

Post by Major Cooke »

So it all must be an action the whole way through. Alright.

Dumb question, can they be ...'cast' into action? I'm expecting a no to that.
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] 'invoker' isn't recognized in named functions

Post by Graf Zahl »

Of course not. The 'action' qualifier adds two hidden parameters. Those cannot be magically added back.

The cases you need these parameters are also very rare. They are really only needed when calculating state jumps or really needing to know where they originate from. In the vast majority of situations you don'T need access to a custom inventory item and the weapon can also be retrieved through player.ReadyWeapon, once player_t is available.
If you examine the regular weapon functions you'll see that almost none of them ever accesses these two parameters.

My general recommendation is to avoid them wherever possible.
Post Reply

Return to “Closed Bugs [GZDoom]”