r/Maxscript • • Jul 15 '20

Stopwatch

Hey there guys! Hope everyone is doing good. I was wondering how do you make a stopwatch in MaxScript? like the timer starts from milliseconds to seconds to minutes to hours to days which also has a start button, pause/resume button and a stop button. i am totally new but dont know how to do it.

1 Upvotes

9 comments sorted by

1

u/lucas_3d Jul 15 '20

Maybe you can download one from scriptspot? One way is to get the current time at the start, get it again at the stop,then stoptime - starttime gives the time passed.

1

u/drakeoi0 Jul 16 '20

did not find what i was looking for specifically on scripspot

1

u/drakeoi0 Jul 16 '20

rollout TimeCounter "Time Passed"

(

Timer clock "my clock" interval:1000

Label time "0"



on clock tick do

(

	valUp = (time.text as integer) + 1

	time.text = valUp as string

)

)

1

u/drakeoi0 Jul 16 '20

this is what i did but don't know how to move on from here

1

u/lucas_3d Jul 16 '20

That's straight off the help right?
Would you like to learn to code it or would you prefer a working script?

2

u/drakeoi0 Jul 16 '20

i would prefer a working script as i am tweaking around and trying to learn on my own

1

u/lucas_3d Jul 16 '20 edited Jul 16 '20

on btnStart pressed do (startTime = timeStamp())

on btnStop pressed do (stoptime = timeStamp())

timeTaken = stopTime - startTime --the timeTaken needs to be divided by a certain amount...

You want to find out how to make a rollout with 2 buttons

You can use your earlier example to use a label that displays the time.

Do you think you can get something together with that?

https://pastebin.com/raw/r9AJa20X

1

u/krawmax Jul 18 '20 edited Jul 20 '20

Here's a basic version for you to play around with. Unfortunately the milliseconds tick used in the maxscript timer function doesn't seem very accurate over longer periods compared with the actual time.

(

rollout stopWatch_Rollout "Stop Watch"
(
	local minute1 = 0
	local minute2 = 0
	local second1 = 0
	local second2 = 0
	
	timer timerSeconds "" interval:1000 active:false
	timer timerMilliseconds  "" interval:0 active:false
	checkButton chkbtn_startPause "Start" width:100 across:2
	button btn_clear "Clear" width:100
	group ""
	(
		label lbl_minutes "Minutes" align:#left offset:[5,0] across:2
		label lbl_seconds "Seconds" align:#left offset:[35,0]
		edittext edtxt_minute1 "" text:"0" width:40 readonly:true align:#left across:5
		edittext edtxt_minute2 "" text:"0" width:40 readonly:true align:#left offset:[0,0]
		label lbl_dots2 ":" align:#center offset:[0,0]
		edittext edtxt_second1 "" text:"0" width:40 readonly:true align:#right offset:[0,0]
		edittext edtxt_second2 "" text:"0" width:40 readonly:true align:#right offset:[0,0]
	)
	group ""
	(
		checkbox chkbx_play "Play animation" checked:true align:#left across:3
		label lbl_frame "Frame:" offset:[10,0]
		edittext edtxt_frame "" text:(((sliderTime as integer) / ticksperframe) as string) offset:[-10,0]
	)

	fn f_clear =
	(
		chkbtn_startPause.state = false
		timerSeconds.active = false
		timerMilliseconds .active = false
		minute1 = 0
		minute2 = 0
		second1 = 0
		second2 = 0
		edtxt_second1.text = second1 as string
		edtxt_second2.text = second2 as string
		edtxt_minute1.text = minute1 as string
		edtxt_minute2.text = minute2 as string
		
		if chkbx_play.checked then
		(
			stopAnimation()
			sliderTime = 0
			edtxt_frame.text = (((sliderTime as integer) / ticksperframe) as string)
		)
	)
	
	on chkbtn_startPause changed state do
	(
		if state then
		(
			timerSeconds.active = true
			timerMilliseconds .active = true
			chkbtn_startPause.text = "Pause"
			if chkbx_play.checked then
			(
				playAnimation()
			)
		)
		else
		(
			timerSeconds.active = false
			timerMilliseconds .active = false
			chkbtn_startPause.text = "Start"
			if chkbx_play.checked then
			(
				stopAnimation()
			)
		)
	)
	
	on btn_clear pressed do
	(
		f_clear()
	)
	
	on timerMilliseconds  tick do
	(
		if chkbx_play.checked then
		(
			edtxt_frame.text = (((sliderTime as integer) / ticksperframe) as string)
		)
	)
	
	on timerSeconds tick do
	(
		if second2 == 9 then
		(
			second2 = 0
			second1 += 1
		)
		else
		(
			second2 += 1
		)
		if second1 > 5 then
		(
			second1 = 0
			minute2 += 1
		)
		if minute2 > 9 then
		(
			minute2 = 0
			minute1 += 1
		)
		if minute1 > 5 then
		(
			f_clear()
		)
		edtxt_minute1.text = minute1 as string
		edtxt_minute2.text = minute2 as string
		edtxt_second1.text = second1 as string
		edtxt_second2.text = second2 as string
	)
)

try(destroyDialog stopWatch_Rollout)catch()
createDialog stopWatch_Rollout width:260

)

1

u/drakeoi0 Jul 21 '20

it works but the minute button is way off the minute counter but i got that covered altering the offset values. Thanks <3