Embedded script run multiple times each frame

Discuss Moho bugs (or suspected bugs) with other users. To report bugs to Smith Micro, please visit support.smithmicro.com

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Embedded script run multiple times each frame

Post by 7feet »

In doing a little debugging on my embedded scripts, I noticed something I thought was pretty strange. For each frame, the script is executed a minimum of 3 times (including during normal playback or using the buttons to go one frame at a time), often 6 if you drag the pointer on the timeline. And, if you hold the mouse button down after having dragged on the timeline and the mouse moves even a tiny bit (even if you are on the same frame) it runs through another set of 3 iterations. Now, I know the embedded scripting is still experimental (but really cool), it seems if you do something complex, or have a bunch of them, it could get a bit costly.

But more of a question that it brought up: is it just the embedded script interface, or is Moho evaluating everything for every frame that it renders during playback. Unless that's something that Moho has to do, it seems like it could easily explain the sluggish playback as scenes become more complicated.

I made 2 little embedded scripts to display this.

Code: Select all

function LayerScript(moho)
	local frame = moho.frame
	if frame == 0 then 
		oldframe = 0
		oldframecount = 1
		print("Resetting")
	end
end
and

Code: Select all

function LayerScript(moho)
	local frame = moho.frame
	if oldframe == frame then 
		oldframecount = oldframecount + 1
	else 
		oldframe = frame
		oldframecount = 1
	end
	print("Frame#",frame, "Frame interations",oldframecount)
end
Put them on any 2 layers in a project and you can see exactly what I'm talking about. Just thought it would be worth pointing out.
User avatar
Lost Marble
Site Admin
Posts: 2354
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Re: Embedded script run multiple times each frame

Post by Lost Marble »

7feet wrote:But more of a question that it brought up: is it just the embedded script interface, or is Moho evaluating everything for every frame that it renders during playback.
It's just embedded scripts. This can be improved for the future, but for now embedded scripts do get evaluated more than is strictly necessary. It's not happening for everything in the layer, just the script.
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

Okay, that clears that up. Thanks.
Post Reply