Script seems to be kept running

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Script seems to be kept running

Post by rylleman »

In Moho12 after I've run one of my scripts, whenever I try to delete shapes (select points and press delete) I get an error message in Lua console saying:

Code: Select all

.../DR_move-shape-to-new-layer.lua:70: attempt to index local 'mesh' (a nil value)
No points are deleted.

Why do Lua console complain about my script when I use a completely different thing (delete points)?

The script worked fine up to Anime Studio 11.

I tried to rename mesh to something else in my script if perhaps it blocks mesh that is used in other functions, but Lua console just complains about this new name instead.

The script:
https://dl.dropboxusercontent.com/u/281 ... -layer.lua
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Script seems to be kept running

Post by hayasidist »

looks to me as though you're redefining global functions MOHO.SelectedPointList and MOHO.DeleteSelectedPoints

so any other script that tries to call them after your script has run will call your version, not the standard ones.

What I'd try is to define them as local functions e.g. local function sel_pts(mesh)

and them call them passing mesh e.g. l = sel_pts(mesh) remembering that the scope of l (which you've defined as local in SelectedPointList) probably means that you'll need a table in the calling routine if you want to use the list (isn't clear to me that you need selected point list though)

IOW:

(you enter this with some points selected - probably worth checking this)
Duplicate layer
In the duplicate: select inverse and delete selected
in the original: delete selected

Maybe worth considering delete selected as working from high to low - that way no need to recount points every time.
max = mesh:CountPoints()
for ptNum = max-1, 0, -1 do
...

Your thoughts???
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Re: Script seems to be kept running

Post by rylleman »

Ha, yes, that was the reason... Thank you!

I remember now that when I wrote the script I couldn't for some reason call those function from lm_utilities so I just copied them into my script which worked at the time.
My quick and dirty fix for now was to rename the functions. It's ugly and my intention is to fix the call to lm_functions when I get some time rather than localizing them.

As for your second suggestion I'll look into this when having some spare time. thank you, it seems clever.
Post Reply