Of ZScript And Delay()

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
Kinsie
Posts: 7402
Joined: Fri Oct 22, 2004 9:22 am
Graphics Processor: nVidia with Vulkan support
Location: MAP33
Contact:

Of ZScript And Delay()

Post by Kinsie »

In all of my past mods, I've committed the cardinal sin of doing elaborate gameplay mechanic things in the map scripting language, ACS. In the past this has been due to ZScript not, you know, existing, but now I don't really have much of an excuse anymore... except for one. Delay().

I use Delay() a shit-ton in my ACS game mode stuff, whether for pulling off looping timers like in Reelism or FauxDM or having events or information-presentation occur in a not-all-at-once fashion (think Reelism and its gradual revealing of and activation of the slots at the start of each round). ZScript does not have this, because it's more of an actual programming language than ACS, which is understandable, but damned if it doesn't drive me mad when I want to make mods with sane array handling and not having to run a compiler every time I make a change.

Earlier tonight TheZombieKiller threw together a proof of concept for doing something akin to delay() in ZScript, by way of a switch-case statement. Given that a.) someone else might have the same problem or b.) someone else might have a better idea on doing this, I thought I'd post this here on the forums to try and discuss how to do things like this in a form that I can read when it's not nearly 4am.

I can probably do some cool stuff with this, but if someone knows a better way, or a way that can be better handled by someone who's as bad a programmer as I am, I'm all ears :)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49223
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Of ZScript And Delay()

Post by Graf Zahl »

That's probably the best you can get. The ZScript VM is really more like a virtual CPU (or a real one when JITed) and you cannot simply halt that. What ACS does behind the scenes of Delay is actually very similar - it stores the script's execution pointer and resumes execution once the timer has elapsed.

I have to say that this Coroutine class is actually very clever and solves the most unpleasant part of halting event driven code quite nicely.
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: Of ZScript And Delay()

Post by The Zombie Killer »

The ZScript compiler could potentially emit something similar behind the scenes for an async/await feature, but I'm unfamiliar with most of the ZScript compiler code and assume that would be a tall order at present.
Graf Zahl wrote:I have to say that this Coroutine class is actually very clever and solves the most unpleasant part of halting event driven code quite nicely.
It was somewhat inspired by how async/await is handled by the C# compiler, combined with the language's concept of 'iterator methods'. It does indeed work rather nicely in the absence of compiler support.
User avatar
m8f
 
 
Posts: 1454
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Location: Siberia (UTC+7)
Contact:

Re: Of ZScript And Delay()

Post by m8f »

I've used a different approach to delayed actions: https://github.com/mmaulwurff/m_gizmos/ ... mg_junk.zs
User avatar
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland
Contact:

Re: Of ZScript And Delay()

Post by MFG38 »

I've found myself grieving at the lack of a Delay function in ZScript as well. But that coroutine should come in handy.
Post Reply

Return to “Scripting”