[Zscript] How do I access a custom player variable?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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!)
elSebas54
Posts: 5
Joined: Sat Apr 09, 2022 5:25 pm

[Zscript] How do I access a custom player variable?

Post by elSebas54 »

I just need to know how to make weapons and usable items read and change the variables of the playerpawn.
The problem is the pointers and casting but i just never figured out how to do that.
7Soul
Posts: 18
Joined: Sat Mar 13, 2021 6:47 pm

Re: [Zscript] How do I access a custom player variable?

Post by 7Soul »

In normal functions you can access the player actor with the owner.player.mo pointer, but in action functions you use player.mo. More help can be found in the zscript entry guide: https://jekyllgrim.github.io/ZScript_Ba ... prite.html
elSebas54
Posts: 5
Joined: Sat Apr 09, 2022 5:25 pm

Re: [Zscript] How do I access a custom player variable?

Post by elSebas54 »

Sorry but this hasn't helped, I've read that guide but i still don't know what to do.
So to clarify what i want with an example:

Code: Select all

Class somthng : DoomPlayer
{
  Float LFX;
}

Class Someweapon : Weapon
{
States
  {
   Fire:
   TNT1 A 1 {
   ???.LFX += 5 //which pointer?
   }
   Goto Ready
  }
}
Here i want to make the weapon increase the player's variable by 5, but i don't know what pointer i have to use, i know that i have to use casting but i never understood that. What do i have to do next?
User avatar
Virathas
Posts: 220
Joined: Thu Aug 10, 2017 9:38 am

Re: [Zscript] How do I access a custom player variable?

Post by Virathas »

1) Floats are ACS variables, you are either looking for int or double.
2) To refer to the wielder of the weapon from a weapon you can use "invoker.owner". Invoker is the weapon itself, and owner is the, well, owner of the weapon.

But this all will not be enough to access a custom variable of a player(or any other class). You need to cast the variable, in your example: "somthng(invoker.owner).LFX".

I'd recommend reading a bit more about ZScript basics, but this should help you get going
7Soul
Posts: 18
Joined: Sat Mar 13, 2021 6:47 pm

Re: [Zscript] How do I access a custom player variable?

Post by 7Soul »

I think this would be it:

Code: Select all

Class Someweapon : Weapon
{
States
	{
	Fire:
		TNT1 A 1 {
			let player = somthng(player.mo);
			player.LFX += 5;
		}
		Goto Ready; // this will crash because you still need to define Ready and the other weapon states
	}
}
The link I posted above also has a tutorial about casting so you should check it out
elSebas54
Posts: 5
Joined: Sat Apr 09, 2022 5:25 pm

Re: [Zscript] How do I access a custom player variable?

Post by elSebas54 »

Thank you, i finally understood casting in got the weapons working :)
elSebas54
Posts: 5
Joined: Sat Apr 09, 2022 5:25 pm

Re: [Zscript] How do I access a custom player variable?

Post by elSebas54 »

Now i have another problem, i want to change multiple variables with a custom action

Code: Select all

Void MoveLFist(int x = 0, int y = 0, int a = 0)
{
 FightyMarine(Invoker.owner).LFX = x; FightyMarine(Invoker.owner).LFY = y; FightyMarine(Invoker.owner).LFA = a;
}
But when i run this i get the error unknown identifier 'invoker', what do i do?
User avatar
Virathas
Posts: 220
Joined: Thu Aug 10, 2017 9:38 am

Re: [Zscript] How do I access a custom player variable?

Post by Virathas »

That is because this is not an action function. I wanted to give you some reference to action functions, but alas, i cannot find anything on the wiki.

You can either remove "invoker" in this function, since when you call the function weapon will become the "self" or you can change Void into Action Void. From what i've noticed, it is best to use action functions in weapons, but i cannot tell you why.
Some more info about what exactly is the invoker:
[wiki]ZScript_special_words[/wiki]
User avatar
ramon.dexter
Posts: 1241
Joined: Tue Oct 20, 2015 12:50 pm
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [Zscript] How do I access a custom player variable?

Post by ramon.dexter »

Please, show us whole defintion of the affected class, not just snippets of code.
elSebas54
Posts: 5
Joined: Sat Apr 09, 2022 5:25 pm

Re: [Zscript] How do I access a custom player variable?

Post by elSebas54 »

Code too big and messy, and Action Void worked, Thank you again.

Return to “Scripting”