[Solved][ZScript] Help with TryPickup()

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

[Solved][ZScript] Help with TryPickup()

Post by D2JK »

Could anyone help me with overriding the TryPickup() function? Vaecrius already tried to help me in the "How to ZScript" topic, but we couldn't make it work (Thanks Vaecrius, appreciate your effort).

Even this simple attempt gives me an error upon a pickup attempt: VM execution aborted: tried to read from address zero. In function parameter "self".

Code: Select all

Override bool TryPickup(actor Toucher)
  {
   return Super.TryPickup(Toucher);
  }
I'd be grateful if someone could show me the code for a working example with an extra if-check included in there(any sort of check would do fine).
Last edited by D2JK on Tue Jun 20, 2017 2:13 pm, edited 1 time in total.
User avatar
Fishytza
Posts: 781
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: No Preference
Contact:

Re: [ZScript] Help with TryPickup()

Post by Fishytza »

Not sure why an if check is needed, but here's a working example.

Code: Select all

version "2.5"

Class MedMakesUJump : Stimpack replaces Stimpack
{
	//This stimpack will make you hop on successful pickup
	override bool TryPickup(in out Actor toucher)
	{
		bool result = Super.TryPickup(toucher);
		if( result ) toucher.Vel.Z = 20;
		return result;
	}
}
EDIT
The reason your example crashes is because "actor Toucher" must be "in out actor Toucher". That's what I did anyway.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: [ZScript] Help with TryPickup()

Post by D2JK »

Neat, thank you very much! You're right; that small change would have been enough to let me proceed with this.

I also noticed that "out actor Toucher" seems to work as well, but then, I have no idea if omitting the "in" will have negative consequences at some point.

Lastly, since you wondered; I wanted to implement additional if - checks such as:

Code: Select all

if (toucher.GetPlayerInput(INPUT_BUTTONS)  &  BT_CROUCH)
 return Super.TryPickup(toucher);
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49073
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Help with TryPickup()

Post by Graf Zahl »

D2JK wrote:I have no idea if omitting the "in" will have negative consequences at some point.
The 'in' is mostly syntactic sugar right now. In combination with an 'out' variable it would normally tell the function that the value being passed is readable but doing that properly was causing some logical issues in the compiler.

Normally when overriding a virtual function the entire signature (i.e. return value and all parameter types including qualifiers) need to be identical.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: [ZScript] Help with TryPickup()

Post by Gutawer »

D2JK wrote: Lastly, since you wondered; I wanted to implement additional if - checks such as:

Code: Select all

if (toucher.GetPlayerInput(INPUT_BUTTONS)  &  BT_CROUCH)
 return Super.TryPickup(toucher);
It probably won't matter for booleans, but it's a better idea to use && for multiple checks in one statement - & is bitwise AND, and can cause unexpected behaviour if you are working with ints.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: [Solved][ZScript] Help with TryPickup()

Post by D2JK »

Thanks, I'll keep that in mind.
Locked

Return to “Editing (Archive)”