CamtheCat Posted May 22, 2012 Okay, so I'll be the first to admit that I suck at math, so for the past few days I've been wracking my brain trying to figure out how to get a modulus operator to work for an advanced timer, if at all possible. I searched on the ZDoom Wiki about implementing on-screen timers via print & HUD Message, & found this nice ACS script example: ------------------------------------------------------------------- script 1 ENTER { int t; while(TRUE) { t = Timer() / 35; HudMessage(d:t/60, s:":", d:(t%60)/10, d:t%10; HUDMSG_PLAIN, 1, CR_RED, 0.95, 0.95, 2.0); Delay(35); } } ------------------------------------------------------------------- But this timer's smallest unit of time is the 'second', & what I am trying to accomplish is to basically make a more advanced timer that counts even more accurately to 'tenths of a second'. Now, I don't know if this is even possible due to the limitations of using 'tics' as units of time instead of 'seconds', but it at least seemed mathematically possible, but I am stumped how to get the timer to correctly tally 'tenths of a second'. I even tried some pretty crummy math to get 35 'tics' = 1 'second' to be the same as 3.5 'tics' = 1/10th of a 'second' or (35/10) 'tics' = 1/10th of a 'second', but again, I suck at modulus operators. So...is this even possible at all, or is the 'second' the smallest unit of time able to be calculated in a DOOM timer? 0 Share this post Link to post
boris Posted May 22, 2012 Did you try to calculate with fixed point values instead of integers? Dunno how it's handled in ACS, but my guess is that something like 35/10 is 3 and not 3.5 (i.e. no type conversion). 0 Share this post Link to post
RestlessRodent Posted May 23, 2012 You can use leap time! Get the current time in tics, divide that by 10 and you get your tenths of a second. Then for every other run, add 1 to that current time. 0 Share this post Link to post
scifista42 Posted May 23, 2012 The solution can look like this: -------------------------------------------------- script 1 ENTER { int t; int t2; while(TRUE) { t2 = Timer(); t = t2 / 35; HudMessage(d:t/60, s:":", d:(t%60)/10, d:t%10,s:":",d:(t2%35)*10/35; HUDMSG_PLAIN, 1, CR_RED, -0.9, 0.95, 2.0); Delay(2); } } -------------------------------------------------- The "-0.9" as x parameter is just for better visual appearance. 0 Share this post Link to post
CamtheCat Posted May 23, 2012 scifista42 said: The solution can look like this: -------------------------------------------------- script 1 ENTER { int t; int t2; while(TRUE) { t2 = Timer(); t = t2 / 35; HudMessage(d:t/60, s:":", d:(t%60)/10, d:t%10,s:":",d:(t2%35)*10/35; HUDMSG_PLAIN, 1, CR_RED, -0.9, 0.95, 2.0); Delay(2); } } -------------------------------------------------- The "-0.9" as x parameter is just for better visual appearance. Damn, see, I would have never figured that out with my half-assed math. Thank you all for taking the time to respond & provide your own solutions. 0 Share this post Link to post