Notifications
Clear all

[Closed] Run function every nth sec?

Is there any simple/compact way to do a loop that runs a function every nth sec?

5 Replies
 PEN

sleep

Is that what you are looking for?

1 Reply
(@patan77)
Joined: 11 months ago

Posts: 0

Perfect, thanks, exactly what I was looking for. though it don’t really work the way i want it, cause max basically freezes.

Just as a test I want to have an object rotate without the “time slider” moving.

mybox = box()

for i = 1 to 10 do 
(
	windows.processPostedMessages()
	rotate mybox (eulerangles 0 0 10)
	sleep 1
)

you have to use timer (the MXS rollout control is preferable vs .NET)

1 Reply
(@patan77)
Joined: 11 months ago

Posts: 0

Yeah thanks, now it works exactly how I wanted it

Example code:

mybox = box()

theTimer = dotNetObject "System.Windows.Forms.Timer"
fn rotateBox = (
If ( isValidNode mybox )  then
	(
	rotate mybox (eulerangles 0 0 10)
	)
	else
	(
		theTimer.stop()
	)
)
dotnet.addEventHandler theTimer "tick" rotateBox
theTimer.interval = 1000
theTimer.start()
--theTimer.stop()

EDIT Added a check if box deleted so, max dont crash if you would delete the box.

Hi, I have used timer in one of my past time scripts. You can find how I have done thru using timer in the stop watch script… you can find them @:

http://teckiraa.blogspot.in/