Page 1 of 1

Embedded script run multiple times each frame

Posted: Sun Oct 16, 2005 6:32 pm
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.

Re: Embedded script run multiple times each frame

Posted: Fri Oct 21, 2005 7:21 pm
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.

Posted: Fri Oct 21, 2005 10:50 pm
by 7feet
Okay, that clears that up. Thanks.