EventHandlers, Parsing Lumps( and some other stuff)

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
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

EventHandlers, Parsing Lumps( and some other stuff)

Post by ZippeyKeys12 »

So I was looking for help with two main things:
EventHandlers:
  • Can I register an EventHandler during runtime? I have handlers that are only necessary when certain classes are chosen so I don't want to run them when that class isn't chosen.
    Does it matter if vars that effect the player are in the EventHandler or in the player class?
    Is there a reasonable max to EventHandlers? Where it begins to cause performance or other problems.
Parsing Lumps:
  • Can I evaluate a String like: "4+3*4" to =16? Right now I've written my own method to do it but I was wondering if there was a builtin way to do it.
    Can I execute strings as a ZScript file or #include using a variable? Extension of ^
    Is there a way to read binary formats?
For other stuff:
  • Is there a way to execute something and not wait for it to finish? Running it in a seperate 'thread'
    For procedurally generating part of a map do I just use polyobjects and move them using ACS?(Kind of mapping :twisted:)
    Is there some ID unique to the user I can retrieve in Zscript or ACS for said generation?
    If my weapon animations have many different variations and conditions, can I animate it via a ZScript method instead of States?
    Do I have to morph the player to change their height that isn't crouching?
Any help would be appreciated :D!
I'm brain-dead tired right now so sorry if none of this makes senseUmm, I forgot to press submit...
RaveYard
Posts: 194
Joined: Fri Apr 12, 2013 10:51 am

Re: EventHandlers, Parsing Lumps( and some other stuff)

Post by RaveYard »

Can I register an EventHandler during runtime? I have handlers that are only necessary when certain classes are chosen so I don't want to run them when that class isn't chosen.
Going through EventHandlers, it seems to inherits from class Object, which contains "Destroy" method.
I have no idea if it is valid behavior for EventHandlers to self-destruct, so do it at your own peril.
Does it matter if vars that effect the player are in the EventHandler or in the player class?
Having the variable in EventHandler means that you have single instance of EventHandler that contains these variables for all players, thus they share them.
If you use it in player, it means each individual player has his own variables, but be careful as respawning causes creation of new PlayerPawn and the variables aren't passed on to the new body.
Is there a reasonable max to EventHandlers? Where it begins to cause performance or other problems.
Depends on the performance of each individual's computer. Though consider that using more EventHandlers means that the engine has to do more ZScript calls. But your code might be more readable and reusable which in most cases is a far better benefit over few microseconds. Besides, GZDoom (on my computer) already runs mostly at half the speed it used to, before ZScript was added.
Can I evaluate a String like: "4+3*4" to =16? Right now I've written my own method to do it but I was wondering if there was a builtin way to do it.
As far as I know the only part of GZDoom capable of this is the ZScript parser/compiler.
So, no.
Can I execute strings as a ZScript file or #include using a variable? Extension of ^
Not sure what you mean by "execute strings as a ZScript file", but if I'm guessing correctly, you mean compiling ZScript during runtime.
ZScript is only processed during the startup, so no.
But feel free to write a ZScript parser and a virtual machine in ZScript :twisted: (But seriously, why would you do that?)
Is there a way to read binary formats?
I don't think so. But I could be wrong.
Is there a way to execute something and not wait for it to finish? Running it in a seperate 'thread'
Just to clarify, there are no threads for ZScript and other logic. When ZScript is invoked from the engine, the called function must eventually reach a return, otherwise GZDoom freezes.
However let's assume you have some insane code that actually takes long enough time to run to cause FPS drops.
The closest and simples you can do is use an Actor to split the task over few ticks.
For example:
Spoiler:
Or you can use a Thinker instead.
For procedurally generating part of a map do I just use polyobjects and move them using ACS?(Kind of mapping :twisted:)
Possibly, but the performance is going to be poor. Depends on the complexity of such thing. If you want slight variety then fine, but if you're going to build entire maps, you're better off just using "Doom OBLIGE".
Is there some ID unique to the user I can retrieve in Zscript or ACS for said generation?
No.
Why would you need such thing in a first place?
Perhaps you could create a CVar and generate such number/string into it. Again, it's not guaranteed to be unique to each (G)ZDoomer out there and it'll pretty much be just bound to the config file.
Still, why?
If my weapon animations have many different variations and conditions, can I animate it via a ZScript method instead of States?
I assume you could do something like that, but it would be much simpler to use either "----" or "####" specials.
https://zdoom.org/wiki/Sprite#Special_names
But regardless, It's probably possible to do something using

Code: Select all

//functions located in struct PlayerInfo
SetPSprite
GetPSPrite
FindPSprite
//functions located in class Actor
FindState
A_SetTics
Dunno, never bothered with it.
Do I have to morph the player to change their height that isn't crouching?
No. From my experience crouching and etc. are horrible messy functions which do some weird stuff to the player's height which make it really painful to actually change the height in the first place.
But it's doable without morphing.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: EventHandlers, Parsing Lumps( and some other stuff)

Post by Apeirogon »

RaveYard wrote:
Do I have to morph the player to change their height that isn't crouching?
No. From my experience crouching and etc. are horrible messy functions which do some weird stuff to the player's height which make it really painful to actually change the height in the first place.
But it's doable without morphing.

What?
RaveYard
Posts: 194
Joined: Fri Apr 12, 2013 10:51 am

Re: EventHandlers, Parsing Lumps( and some other stuff)

Post by RaveYard »

Apeirogon wrote:
RaveYard wrote:
Do I have to morph the player to change their height that isn't crouching?
No. From my experience crouching and etc. are horrible messy functions which do some weird stuff to the player's height which make it really painful to actually change the height in the first place.
But it's doable without morphing.

What?
Oh, I see. Turns the issue was that there's an extra variable "FullHeight" for the playerpawn. :oops:
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: EventHandlers, Parsing Lumps( and some other stuff)

Post by The Zombie Killer »

You can read binary data, yes. Using the Wads API.
Using this, combined with String.CharCodeAt, you can read binary data from arbitrary lumps within a wad, pk3 or pk7.

Note that you will need to bitwise AND the result of CharCodeAt by 255, so:

Code: Select all

int lump = Wads.CheckNumForFullName("path/to/lump.bin");
let data = Wads.ReadLump(lump);
let firstByte = data.CharCodeAt(0) & 255;
So, if you wanted to read a 32-bit integer from position 0 for example:

Code: Select all

int number =
    ((data.CharCodeAt(0) & 255) <<  0) |
    ((data.CharCodeAt(1) & 255) <<  8) |
    ((data.CharCodeAt(2) & 255) << 16) |
    ((data.CharCodeAt(3) & 255) << 24);
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: EventHandlers, Parsing Lumps( and some other stuff)

Post by Apeirogon »

Why someone need use binary format? Prevent mod for changing?
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: EventHandlers, Parsing Lumps( and some other stuff)

Post by The Zombie Killer »

Apeirogon wrote:Why someone need use binary format? Prevent mod for changing?
A number of potential reasons come to mind.
  • It's much easier to read binary data than it is to parse textual data (you could store data in a string cvar and then read it back later)
  • Reading existing binary files that you have no control over the structure of
  • Reading information from existing binary files in a mod (such as graphic lumps or palettes)
It's possible to use more than one palette at a time in ZDoom if you write a small bit of code to read PLAYPAL files and use the Translation struct, so that's another use case.
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: EventHandlers, Parsing Lumps( and some other stuff)

Post by ZippeyKeys12 »

Spoiler: A lot of stuff by RaveYard
Post Reply

Return to “Scripting”