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

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

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

by Graf Zahl » Sat Nov 12, 2016 1:50 am

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.

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

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

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.

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

by Graf Zahl » Fri Nov 11, 2016 6:32 pm

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.

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

by Major Cooke » Fri Nov 11, 2016 5:59 pm

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.

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

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

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"));
   }

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

by Graf Zahl » Fri Nov 11, 2016 5:13 pm

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.

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

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

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"));
   }
}

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

by Major Cooke » Fri Nov 11, 2016 4:50 pm

I think that's limited to design. It will only work in an anonymous function.

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

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

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"));
	}
}

Top