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!)
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 )
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 ! I'm brain-dead tired right now so sorry if none of this makes senseUmm, I forgot to press submit...
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 (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:
class MyMagicalTask : Actor
{
Default
{
+NOGRAVITY;
+NOSECTOR;
+NOBLOCKMAP;
+NOINTERACTION;
FloatPhaseBob 0;
}
States
{
Spawn:
TNT1 A 0;
TNT1 A 35 {
Console.Printf("Hello!");
}
TNT1 A 35 {
Console.Printf("Goodbye!");
}
stop;
}
}
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 )
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
//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.
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.
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.
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:
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.
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 (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:
class MyMagicalTask : Actor
{
Default
{
+NOGRAVITY;
+NOSECTOR;
+NOBLOCKMAP;
+NOINTERACTION;
FloatPhaseBob 0;
}
States
{
Spawn:
TNT1 A 0;
TNT1 A 35 {
Console.Printf("Hello!");
}
TNT1 A 35 {
Console.Printf("Goodbye!");
}
stop;
}
}
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 )
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
//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.
Wow! I really appreciate that you spent time writing such in-depth answers to everything. This is really great, thanks!
Apeirogon wrote:
[wiki=A_SetSize]What?[/wiki]
Are you kidding me... What is this mad sorcery, I've spent entire days trying find a nicer way to change player size and this existed -_- What would I be doing without your masterful use of the wiki...
Spoiler: Knowledge
The Zombie Killer wrote: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: