Returning an integer for currently selected crosshair

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!)
User avatar
JMaszk
Posts: 8
Joined: Sun Oct 30, 2022 2:01 pm
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Returning an integer for currently selected crosshair

Post by JMaszk »

I am trying to make a simple function to return the player's currently selected crosshair as an Integer.
This is inside code of a base class for a weapon, just so you know the context.

Here is the function:

Code: Select all

int GetCurXhair()
{
	return -int(player.ReadyWeapon.Crosshair);
}
Then when I try to use it in another function of the same base class it errors out:

Code: Select all

 self.player.ReadyWeapon.Crosshair = GetCurXhair(); 
"Call to member function GetCurXhair with incompatible self pointer."
I tried invoker.GetCurXhair(); with no success either.
Last edited by JMaszk on Sat Dec 17, 2022 4:53 pm, edited 2 times in total.
Jarewill
Posts: 1447
Joined: Sun Jul 21, 2019 8:54 am

Re: Returning an integer for currently selected crosshair

Post by Jarewill »

Without being able to test the code right now, try to turn GetCurXhair into an action function, like so:
action int GetCurXhair()
This should set the self pointer to be the player instead of the weapon.
User avatar
JMaszk
Posts: 8
Joined: Sun Oct 30, 2022 2:01 pm
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: Returning an integer for currently selected crosshair

Post by JMaszk »

Jeez... It was that simple!! I didn't even notice I wasn't adding action to the function inside of a weapon... :oops:
Simple fix, thank you!

Return to “Scripting”