ACS / ZScript method to track real time?

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
necros
Posts: 19
Joined: Mon Dec 30, 2019 10:26 pm
Contact:

ACS / ZScript method to track real time?

Post by necros »

I'm making a long level and it would be tiresome to listen to the same 2-4 minute midi on loop. What I'd like to do is make a handful of midis that can be played randomly. Problem is, midis don't stop playing when the player enters a menu or drops the console down. Those two actions freeze the in-game time, so delays set in scripts would no longer match with the current time of the midi.
Is there a way to check the real clock time in-game so that even if a player pauses the game, I could still tell if a minute had passed in real time?

And yes, I'm aware of ways around this, such as just gluing everything together in one midi file, but you would run short of instrument channels. Another method would be to just make each individual midi have a super long silence at the end of them so they wouldn't loop before a new song was started, but that can lead to a lot of dead air time if the player pauses for more than a few seconds.
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: ACS / ZScript method to track real time?

Post by m8f »

necros
Posts: 19
Joined: Mon Dec 30, 2019 10:26 pm
Contact:

Re: ACS / ZScript method to track real time?

Post by necros »

Are you sure? I get:

Code: Select all

Script error, "D:/Games/Doom/ne_tall/:zscript/necros/musictimer.zs" line 33:
Call to unknown function 'Now'
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: ACS / ZScript method to track real time?

Post by Caligari87 »

That feature was added to GZDoom in August 2020, so yes, pretty sure.

You need to post your code, otherwise it's impossible to tell where you might be going wrong.

8-)
necros
Posts: 19
Joined: Mon Dec 30, 2019 10:26 pm
Contact:

Re: ACS / ZScript method to track real time?

Post by necros »

I couldn't find a link to that article when looking through the wiki, so that's why i was wondering...

Anyway, it's all unfinished at this time but what I was planning on doing, since this is zscript only (as indicated in the article), is to create a 'MusicTimer' object which after spawning drops into an 'idle' state where it runs an update function every 35 tics to change the mass of the object to be whatever int value Now() returns.

Then in an ACS of my map, I can just spawn the object in (outside of my map) and use GetActorProperty(666, APROP_Mass); to get the current mass of the object and then eventually I would write some actual logic to control when and what midi to start.

Here's the MusicTimer class:

Code: Select all

class MusicTimer : Actor
{
	Default
	{
		Mass 0;
	}
	States
	{
		Spawn:
			TNT1 A 1;
		Idle:
			TNT1 A 35 UpdateTime;
			Loop;
	}
}

extend class MusicTimer
{
	void UpdateTime()
	{
		Mass = Now();
	}
}
EDIT: Thanks for that link to the patch notes. I tried using 'SystemTime.Now()' and this works, but it looks like you can't use this on actors?

Code: Select all

Script error, "D:/Games/Doom/ne_tall/:zscript/necros/musictimer.zs" line 26:
Can't call ui function Now from play context (not readable)
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: ACS / ZScript method to track real time?

Post by Blue Shadow »

Would it not be easier if you created a playlist for GZDoom to [wiki=CCMDs:Other#Music_control]play[/wiki]? There's also the option of using one of those "jukebox" mods out there (sorry, I don't have links handy).
necros
Posts: 19
Joined: Mon Dec 30, 2019 10:26 pm
Contact:

Re: ACS / ZScript method to track real time?

Post by necros »

oh, i didn't even know it had that feature...
well, it sounds like this might be the best option for now. also toying with just using acs fading in and out and switching tracks whenever the player gets to specific points in the map.
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: ACS / ZScript method to track real time?

Post by Player701 »

necros wrote:EDIT: Thanks for that link to the patch notes. I tried using 'SystemTime.Now()' and this works, but it looks like you can't use this on actors?

Code: Select all

Script error, "D:/Games/Doom/ne_tall/:zscript/necros/musictimer.zs" line 26:
Can't call ui function Now from play context (not readable)
System time is non-deterministic in the context of the playsim, so you cannot use this function in regular actor classes. However, you can use it in an event handler if you handle the UiTick event.
Post Reply

Return to “Scripting”