Passing player variables to weapon

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)

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: Passing player variables to weapon

Re: Passing player variables to weapon

by rollingcrow » Fri Nov 08, 2019 2:29 pm

Hm, the first method seems to cause a VM abort (read from address zero) depending on where it's called:
Spoiler:
However, the second method works in either place, thank you:
Spoiler:

Re: Passing player variables to weapon

by Boondorl » Fri Nov 08, 2019 12:13 am

If walking is a custom variable then your player variable in the second code snippet won't see it because you're storing it as a regular Actor pointer. You're also calling the wrong pointer in your DoEffect() function.
Spoiler:
The reasoning is a bit complex, but essentially when you call any function from a weapon's states it's actually being called from the player, hence why there's a difference between the self pointer and invoker pointer. When you call a weapon's custom or virtual function that does not have the action keyword, however, the self pointer will refer to the weapon itself. Owner is the pointer you'll be looking for in these cases. Another quirk of this is that in order to access a weapon's variable in one of its states, you'll have to use the invoker pointer e.g. invoker.player would access the weapon's player variable.
Spoiler:
Ultimately, you can just call AstralPlayer(self).walking from a weapon's state to quickly access the variable.
Spoiler:

Passing player variables to weapon

by rollingcrow » Thu Nov 07, 2019 9:33 pm

I am casting a player class to allow its variables to be accessed by a weapon. Is there a way I can increase the scope of the Actor pointer so I don't have to redefine it in every anonymous function?
Spoiler: Weapon class with pointer to player
What doesn't seem to work is defining the Actor pointer outside an anonymous function, which causes "unknown identifier" errors:
Spoiler: Defining "player" outside an anonymous function

Top