Layer scripts run "more than once" on 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
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Layer scripts run "more than once" on each frame

Post by heyvern »

That's about it. It appears that when entering a frame the layer script is activated about 3 times.

I would like to implement specific changes in the layer with out it being run more than once.

Also preview changes like panning or zooming activate the layer script. Panning and zooming should NOT activate a layer script. Only direct editing of bones or points should trigger a layer script. Frame change activation of the layer script should also not effect variables which appears to happen but this could be a result of multiple activations of the script.

-vern
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

I don't think it is a bug.
Not all the Layer Scripts use the frame as its base for work on. Imagine that you want to create an embedded script that do something when something change on the layer but that thing that changes is modified for other scripts or by the animation playback or by a menu entry. For instance, The embedded script do something if there is a keyframe for some certain object (a bone for example) in the current frame. Then the script should be run after the keyframe is added... And you still being at the same frame... So if there is not playback the script wouldn't be called...
How can Moho know what is the variable that the embedded script is waiting its change? The fast solution for that question is call the embedded script everytime tool, menu entry or playback could modify the parameters that the LayerScript have (that remember, the parameter is moho what holds a lot of variables for the current Layer and Moho Document...). I supose it was done in the internal code of Moho and everytime you press a button or a menu entry or ... (I don't really know) the embedded scripts are called.

I think that what you should do (you probably have done yet) is to verify what have changed between call and call. Just registering the current frame and the "old current frame" you can avoid to call the script twice or more times.
Makes it some sense?
-G
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I still think it shouldn't run the script 3 times on each frame. It makes no sense to me. Put a "print()" into any layer script... it is always runs 3 times.

Even if it was "running" to check for other tools or events it should only run when those things take place. When a keyable tool is clicked in the window. Why would a layer script run when you are panning the view or zooming in and out? Panning and zooming are not keyable so they shouldn't effect a script... in my opinion anyway.

The script is very simple. It increments a global variable set on frame 0 based on bone position. It then updates bone position and the variable for the next "frame" or iteration of the script.

Panning and zooming "activates" the script but once you click in the time line or go to a new frame the global variables changed by the script are reset to the frame 0 values.

Maybe I'm incorrect about what the bug is exactly but there is definately a bug in how layer scripts are activated.

-vern
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Hah!

So five minutes after posting...

Code: Select all

    if (frame > 0) then
        if (oldframe ~= nil) then
            if (oldframe ~= moho.frame) then

            --- do your "once per frame stuff" here

            end
        end
        oldframe = moho.frame
    end
The global "oldframe" variable is set to nil on frame 0. This forces the script to run only once per frame!! The bonus is you can still have code that runs constantly on the frame.

I still have the problem with some global variables reseting on each frame though.

-vern
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

That's what I wanted to say to you :wink:
Genete wrote:I think that what you should do (you probably have done yet) is to verify what have changed between call and call. Just registering the current frame and the "old current frame" you can avoid to call the script twice or more times.
Makes it some sense?
-G
-G
Post Reply