ZScript Discussion

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
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm

Re: ZScript Discussion

Post by ibm5155 »

Hmm I see...

for now, is there some ide for developing zscript or are you guys for now developing zscript in a notepad (not the ++) like app? (At least I didn't found in slade3 neither gzdoom builder a text editor bundled with a zscript parser)
User avatar
Kinsie
Posts: 7402
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33

Re: ZScript Discussion

Post by Kinsie »

ibm5155 wrote:Hmm I see...

for now, is there some ide for developing zscript or are you guys for now developing zscript in a notepad (not the ++) like app? (At least I didn't found in slade3 neither gzdoom builder a text editor bundled with a zscript parser)
I just use the SLADE3 text editor. There's no highlighting yet, but it works for me.
User avatar
Major Cooke
Posts: 8193
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript Discussion

Post by Major Cooke »

Indeed. Set it to ZDoom Decorate and it can have at least some. That's all I need.
User avatar
Nash
 
 
Posts: 17455
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript Discussion

Post by Nash »

ibm5155 wrote: Also, can zscript do something that you really cannot do in decorate/acs?
Almost yes. For example, I just did a special effects system (for things like blood, rain FX, smoke - things that require a lot of things to be spawned at once and have a lot of transparency overdraw) that each player in multiplayer can separately configure the density of, and it doesn't desync In multiplayer. :mrgreen:

(The trick is to always spawn the objects, then Destroy() / bInvisible them in BeginPlay)
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript Discussion

Post by ZZYZX »

So I made a PR for the first part of the events, so that Graf can review it before too much is done, and also so that some unrelated enhancements finally get into the master (printf-related).
Brief description in the PR: https://github.com/coelckers/gzdoom/pull/236

Next planned stage is PlayerEventHandler.
Not sure if these are ever used in ZDoom with it's multiplayer model, but for the future:
- PlayerConnected
- PlayerDisconnected
- PlayerJoined - this actually exists in ZDoom and is called ENTER script
- PlayerSpectated
Also:
- PlayerRespawned (including resurrect command!)
- PlayerDied (not sure if we need this, since again we can check if player died using a script that loops and checks health<=0)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49141
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

ZZYZX wrote: - PlayerDied (not sure if we need this, since again we can check if player died using a script that loops and checks health<=0)

Note: For such things an event will always be cheaper than polling it.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript Discussion

Post by ZZYZX »

In that case I probably need to add WorldThingDied/WorldThingResurrected/WorldThingDestroyed too.
ZzZombo
Posts: 317
Joined: Mon Jul 16, 2012 2:02 am

Re: ZScript Discussion

Post by ZzZombo »

Why the interface is made of special classes instead of like it's done nearly everywhere where you have events? You subscribe to an event, and when it fires, your callback function is called with relevant parameters. This way you preserve the context that the code handling an event runs in, while in this system you would also have to establish inter-class communication to send info from event handlers to the real recipient.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript Discussion

Post by ZZYZX »

This is a valid programming pattern.
Also, mixing, say, user input with actor classes is a bad coding practice as it produces highly unreadable and unmaintainable code.
Specialized object should read the user input and decide what to do. Same thing with other events that occur.

If you still think it's needed, give specific examples please.

Also:
ZzZombo wrote:Why the interface is made of special classes instead of like it's done nearly everywhere where you have events?
https://en.wikibooks.org/wiki/X_Window_ ... ib#Example (here you pop events from the queue)
https://www.libsdl.org/release/SDL-1.2. ... mples.html (here you pop events from the queue)
https://www.sfml-dev.org/tutorials/2.0/ ... events.php (here you pop events from the queue)
The three examples above are not suitable for ZScript because they assume you have single event processor in the whole application.
http://www.winprog.org/tutorial/window_click.html (well ok, a bit similar to "subscribing", but you can have one wndproc per window)
http://doc.qt.io/qt-4.8/eventsandfilters.html (here the global event loop calls your CLASSES with the specified VIRTUAL METHODS in them)

Where is this "everywhere" that you are talking of? C# or JS?
In Java you'd also have classes because Java got no concept of anonymous function (I think there's something similar in Java8, but it's not a real anonymous function or delegate anyway — it's an interface, CLASS, with only one method in it).
ZScript doesn't have function pointers either, so here it is — classes. It's way more natural with the existing codebase than trying to put a completely alien approach on top of it.
ZzZombo
Posts: 317
Joined: Mon Jul 16, 2012 2:02 am

Re: ZScript Discussion

Post by ZzZombo »

Delphi, Lua, Javascript, Perl; DotA 2, WinAPI. I could continue listing if I had more time.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49141
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

So what? ZScript doesn't have function pointers or multiple inheritance so the entire discussion is moot.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript Discussion

Post by ZZYZX »

Also, you (ZzZombo) successfully missed the last point in the PR description.

Right now, in WorldLoaded/WorldUnloaded, we only pass IsSaveGame variable.
In the future I'm going to also add kind of previous level info and IsHubTravel, so that we can tell if we travelled from another level (or it's a new game) and if we can return back to that level.

Now, if this is done via delegates/event handlers or virtual method arguments, we'll have to have virtual void WorldLoaded(bool IsSaveGame) and virtual void WorldLoaded3(bool IsSaveGame, LevelInfo prevLevelInfo, bool IsHubTravel), because if you edit the original WorldLoaded to have three arguments, all mods that were using it will break.

The same way variable types could be tweaked, and the only requirement there would be that it has to cast into the same type that older mods assume it to be (i.e. if IsSaveGame becomes an int or an enum, it's perfectly okay in this case, because if (IsSaveGame) checks will still work).

That was one of the main reasons to put it exactly this way and not something else.
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm

Re: ZScript Discussion

Post by ibm5155 »

Nash wrote:
ibm5155 wrote: Also, can zscript do something that you really cannot do in decorate/acs?
Almost yes. For example, I just did a special effects system (for things like blood, rain FX, smoke - things that require a lot of things to be spawned at once and have a lot of transparency overdraw) that each player in multiplayer can separately configure the density of, and it doesn't desync In multiplayer. :mrgreen:

(The trick is to always spawn the objects, then Destroy() / bInvisible them in BeginPlay)
Wait so you made something like the zandronum's clientside acs code? where you can just Spawn rain around your câmera and not around each player (so in this case it'll avoud a huge lag D:)
And does it work if you coop spy?
User avatar
Major Cooke
Posts: 8193
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript Discussion

Post by Major Cooke »

Nash wrote:
Almost yes. For example, I just did a special effects system (for things like blood, rain FX, smoke - things that require a lot of things to be spawned at once and have a lot of transparency overdraw) that each player in multiplayer can separately configure the density of, and it doesn't desync In multiplayer. :mrgreen:

(The trick is to always spawn the objects, then Destroy() / bInvisible them in BeginPlay)
I too would love to hear more about this. This is one of the biggest reasons why D4D right now is single player only, because of the customizations being tailored to pretty much just one player.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript Discussion

Post by ZZYZX »

There! There, Eruanna, are modders that do care about demo and networking compatibility!
Are you still so sure that you need to force them into not being able to affect playsim at the cost of not adding useful features?

(still on the feature query thing)

On topic: changed multiple handler types into single handler type + multiple data types, to avoid confusion and too strict specialization of handlers.
i.e. instead of WorldEventHandler you now have a regular EventHandler, but WorldLoaded takes an object called WorldEvent with all the relevant data in it.

Return to “Scripting”