Trying to get a reliable anytime LayerScript() call counter...
Posted: Sun Sep 18, 2022 3:32 am
Hi, I'm several days after something that sounded simple at first but here I'm kind of stagnant and I wanted to be sure I'm not missing something that finally could make it that simple... I wanted to implement a reliable counter of how many times a layer script is run or, in other words, how many times the function "LayerScript(moho)" is called each time Moho detects a change that triggers layer scripts to run.
The tricky part is that I'm trying to do it no-matter-what, I mean, I can reset the counter in base of some changeable parameter that let me do it, for example, using the typical current frame change for simplicity (although it could be layer's stacking order, or anything like that) I'd do it as follows:
And as a result...

...I'll have I think a reliable way of knowing if I'm in the first, second, three... call of the LayerScript function because I can ensure runCount gets reset to 1 in the very first run of the cycle. But as I said, what if I wanted to know this all the time and not in base of a changeable state like, in this case, the current frame? Do you think there could be a way of knowing for sure in which run/call of the embedded script cycle for each Moho change you are?
Oh, or do you think I could make use of any of this Lua's debug functions for returning an info like this? It calls my attention specially those "debug.sethook()" and "debug.gethook()", but being all this debug library an unknown part of Lua for me it's being hard to figure out how to really use them, for now at least...
Well, that's all and I hope it makes sense (or not sound too trivial/silly
) this way exposed... Thanks in advance for any insight you could come up with, if you think it's somehow possible and you don't mind!
The tricky part is that I'm trying to do it no-matter-what, I mean, I can reset the counter in base of some changeable parameter that let me do it, for example, using the typical current frame change for simplicity (although it could be layer's stacking order, or anything like that) I'd do it as follows:
Code: Select all
function LayerScript(moho)
if oldFrame ~= nil and runCount ~= nil then
if oldFrame ~= moho.frame or runCount < 4 then
if oldFrame ~= moho.frame then
runCount = 1
else
runCount = runCount + 1
end
if runCount == 1 then --do whatever you want in call 1,2,3 or 4
print("\n" .. "- 1st 'LayerScript(moho)' run!")
elseif runCount == 2 then
print("- 2nd 'LayerScript(moho)' run!")
elseif runCount == 3 then
print("- 3rd 'LayerScript(moho)' run!")
elseif runCount == 4 then
print("- 4th 'LayerScript(moho)' run!")
end
print(" runCount: " .. runCount .. ", oldFrame: " .. oldFrame .. ", curFrame: " .. moho.frame)
end
end
oldFrame = moho.frame
end
And as a result...

...I'll have I think a reliable way of knowing if I'm in the first, second, three... call of the LayerScript function because I can ensure runCount gets reset to 1 in the very first run of the cycle. But as I said, what if I wanted to know this all the time and not in base of a changeable state like, in this case, the current frame? Do you think there could be a way of knowing for sure in which run/call of the embedded script cycle for each Moho change you are?
Oh, or do you think I could make use of any of this Lua's debug functions for returning an info like this? It calls my attention specially those "debug.sethook()" and "debug.gethook()", but being all this debug library an unknown part of Lua for me it's being hard to figure out how to really use them, for now at least...
Well, that's all and I hope it makes sense (or not sound too trivial/silly
