[ZScript] Assigning a PlayerPawn's UserCMD

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!)
Post Reply
User avatar
Gustavo6046
Posts: 137
Joined: Sat May 13, 2017 3:11 pm
Location: Brazil
Contact:

[ZScript] Assigning a PlayerPawn's UserCMD

Post by Gustavo6046 »

I was trying to make the ζetaBot's movements compatible universally by assigning forwardMove, buttons, etc to an UserCmd struct and then assigning that struct (even if manually) to the possessed PlayerPawn's player.cmd.

What I may have figured out, is that apparently my struct is treated as a pointer when I assign it to a PlayerInfo, even if that PlayerInfo is a struct I declared in that function, along with the UserCmd; it's a Pointer< NativeStruct<UserCmd> >, but PlayerInfo wants a NativeStruct<UserCmd>.

The usual way - just plain assigning cmd to possessed.player.cmd - would not crash the compiler; it would crash the runtime, accessing a NULL pointer somewhere in the original C code. If this in qzdoom.pk3/zscript/shared/player.txt:

Code: Select all

native @UserCmd cmd;
isn't a pointer when I assign it to a PlayerInfo, why is it treated like such when assigning to its members?

I mean, I could just lazily copy parts of the player code for movement (TweakMove, etc), and make it work from such, but I don't want to, because it would be a bit redundant. Is there any other way? Preferably using UserCMDs?
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: [ZScript] Assigning a PlayerPawn's UserCMD

Post by _mental_ »

Instances of native structs are handled as pointers.
Notice the @ character before the type and check how UserCmd "objects" are used in core ZScript lumps.

As for the crash, post a runnable samples and I'll check what's wrong with it.
User avatar
Gustavo6046
Posts: 137
Joined: Sat May 13, 2017 3:11 pm
Location: Brazil
Contact:

Re: [ZScript] Assigning a PlayerPawn's UserCMD

Post by Gustavo6046 »

Thank you.

It's about ζetaBot, so it crashes if you press kp1 (summonfriend ZetaBot 0). I will updated the download link.

More specifically, the zscript.bot lump.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: [ZScript] Assigning a PlayerPawn's UserCMD

Post by _mental_ »

GZDoom doesn't crash but shows you the following error

Code: Select all

VM execution aborted: tried to write to address zero.
Called from ZTBotController.uploadPlayerInfo at :zscript.bot, line 65
Called from ZTBotController.SetPossessed at :zscript.bot, line 181
Called from ZetaBot.PostBeginPlay at :zscript.bot, line 834
If you will add some debugging output to line 63, for example like this

Code: Select all

console.printf("pinfo == %p", pinfo);
you will figure out why it aborts with the error

Code: Select all

pinfo == 0000000000000000
This clearly shows that pinfo is null. Then how do you suppose GZDoom can access its members? It cannot and notifies you about the problem.
User avatar
Gustavo6046
Posts: 137
Joined: Sat May 13, 2017 3:11 pm
Location: Brazil
Contact:

Re: [ZScript] Assigning a PlayerPawn's UserCMD

Post by Gustavo6046 »

I knew there was something like that happening, but just doing another PlayerInfo and THEN assigning it would not work because it could not convert a NativeStruct pointer to instance, or whatever it was.

Either way, thanks for helping...
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: [ZScript] Assigning a PlayerPawn's UserCMD

Post by _mental_ »

The problem with your approach is attempt to work with objects that are not fully scriptable.
You cannot make fully functional player using ZScript only. GZDoom creates and manages players and their pawn classes from C++ code.
I suggest you to treat your bots as very advanced monsters instead of trying to fool the engine with a player imposter.
User avatar
Gustavo6046
Posts: 137
Joined: Sat May 13, 2017 3:11 pm
Location: Brazil
Contact:

Re: [ZScript] Assigning a PlayerPawn's UserCMD

Post by Gustavo6046 »

Okay then, thanks.

I have an idea for that - to emulate player movement as closely as possible, copying the TweakSpeeds thing (although I'd like to know how I would work with those functions). I'd also need to know how to use a custom weapon, to use its firing state, and who knows, better suggestions to rate them as well (the current approach is a bit limited).
Post Reply

Return to “Scripting”