Intelligent "Only Active in Mainline" LayerScripts

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Intelligent "Only Active in Mainline" LayerScripts

Post by Rai López »

HI!!! I have been doing the "Rasheed's Scriptnig Course", yes :) ...and I have been reading someting about this there, and I think could be possible but I'm not totally sure... Well, the case is that when you have a layer with some Embedded Script added, and you treat to work with Actions you are continuously receiving error messages in Lua Console Window advertissing about extrange and fearsome (possible) consecuences... Plus (and the most important thing), there's some situations where you don't want Embedded Script be active when you are inside an Action, in example with Embedded Scripts that write keyframes in timeline (cause automatically would destroy your active Action :() ...So I think that must be a Lua Comand or Instruction or something to make an Embedded script "Inactive" meantime you are inside an Action and make it "Active" again when you return to the Mainline, something like this normal Scripts instruction:

Code: Select all

    if (moho.layer:CurrentAction() ~= "") then 
        return
    end
But adapted for Embedded Scripts... Could be SO simple? Well, I HOPE! And I'll continue investigating, but (of course (and as always)) any help/advice/clue it'd be very WELCOMED :) ...THANKS & CIAO!
Last edited by Rai López on Wed Feb 08, 2006 10:25 am, edited 4 times in total.
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

Uf... I'm trying all possible combinations of that code lines and nothing... Actually I'm treating to modificate 7feet's SwitchSlave Embedded Script to make it inactive when you are inside an Action (cause is not a good idea auto-write keys inside actions) and I only obtain message lua errors... I think that must be easy make Embedded scripts be "skipped" if you are inside an Action, isn't? Just in the same way others scripts do, but seems that I've not the key... Well, I'll go on and on...
Last edited by Rai López on Wed Feb 08, 2006 1:35 pm, edited 1 time in total.
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

...Ey! I'VE GET IT!!! :D (finally... :roll: ) Now "Key Writer" scripts will NOT *dEsTRoy* my Actions never more 8) ...Well, a little (very little) step more to get that I want :)
Last edited by Rai López on Wed Feb 08, 2006 10:54 am, edited 2 times in total.
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 8:22 am
Location: sweden
Contact:

Post by rylleman »

Congratulations!
Care to share your discoverys? It might be useful for people when writing other embedded scripts.
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

THANKS!!! :D And... Ey! I love share! (talking about scripting, of course ;)) But seemed to me that nobody was really interested on this... :roll: ahmmm... WELL! Anyway the discovery is not too much inpressive at last, but I think that could be something to take into account for future "Key Writer Embedded Scripts" with Action compatibility :) ...You'll see, I only had to put that above few lines of code in the right place, just before keyframes be writed in timeline and not at first of the script as I was doing... and that was all! Finally all worked fine :) ...But although it take a lot of hous to me, I suppose that someone like you or any else with a "little" scripting knowledges could have discovered it in a second... Then yeah, I think that could be like a good idea if I'll treat to explain then what I'm treating to do/get with all this (that is not a little thing...) just in case you (or anyone) could understand me better, see if someone else could be interested in something similar and... :idea: who knows if even receibe some help! :D Jaja, well... SEE YOU LATER! And THANKS for encourage me to share! :)
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 12:30 am
Location: The Netherlands

Post by Rasheed »

Ramón, it could just be that people didn't respond because they were awed by your audacity to take on scripting. Not so long ago, you wrote that scripting was too difficult for you and now you have taken the first step.

Congratulations! We can never have too many scripters for Moho.

And I'm really curious what you have written so far.
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

Rasheed wrote:Ramón, it could just be that people didn't respond because they were awed by your audacity to take on scripting.
THANK YOU! :D But... :) :| :( :cry: (...Sniff!) Hope... I've still missed/wasted almost a week (including weekend, yes... :cry: ) with all this and I've --> N-O-T-H-I-N-G... Uf, what a madness/depression guys... Basically I've changed my first plans and now I'm treating to get sometning much more simple, but not even... I treat to catch some codes of here and there and I try all the possibities that I can imaginate, but nothing, finally I only obtain Lua errors...

Well, that is the situation, now I'll treat to explain in a few words that I want to get (a little peculiar thing), just in case someone have some clue or advice... I'm treating now to get an Embedded Script that copy current points animation to the zero frame in real time, I mean, you have a circle, in example, and squash it in frame 6, well, but this script should "transmit" the current poin position of all points (all animation data) to the zero frame in real time, so in frame zero always be the"same" that you can see in the cursor position... it seems easy, isn't? But not... The most similar thing that I've could make work is based on that 7feet's SwitchSlave Embedded Script modi-simplification...

Code: Select all

function LayerScript(moho)

	local frame = moho.frame
	
	if (moho.frame ~= 0) then
		local switchName = moho.layer:SwitchValues():GetValue(frame)
		moho.layer:SwitchValues():SetValue(0, switchName) 
	end
end
...to get curret Swich value be transmited to frame zero of the same Switch Layer in realtime, not useful, but at least seems that it works (unaccountably :roll:) and was for me a little hope... And then, of course, I've treated to change the parameters/values and functions, belive me, all possible order/combinations to affect points animation instead Switch animation values, but nothing...

Well, I don't know if I've explained correctly or if somebody could be interested in something like this, but well... I hope someone can let me a little hand or something... THANK YOU! :)
Last edited by Rai López on Tue Feb 14, 2006 3:18 pm, edited 1 time in total.
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

O.K. if I have this:

Code: Select all

function LayerScript(moho) 

	local mesh
	local i
	local mesh = moho:Mesh()

	if ( mesh ~= nil ) then
		local pointCount = mesh:CountPoints()
		for i = 0, pointCount-1 do
			local point = mesh:Point( i )
			
			point.fAnimPos:GetValue(frame)
		end
	end
end
Am I in the right (or better at least) way? My pourpose is obtain the fAnimPos data (or "AnimVec2" data? :? ) of ALL the points in the current frame, but seems that I have problems to make this line works at that point:

Code: Select all

			point.fAnimPos:GetValue(frame)
Hmmm :roll: ...Any idea or advice? THANKS!
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

Hmmm... I'm having troubles specialy when I treat to "get" and "set" the AnimVec2 values cause I need obtain the value of ALL points in the layer (not one or some of they that would be easy to do) and seems that I have no idea of how call'em... I mean, I do the same to call othes functions and variables, like CountPoints, i.e., as Rasheed explain in his Lua tutorials, but I always obtain the same message "attempt to call method 'AnimVec2' (a nil value)" in the Lua Console and any value is procesed... Well, I don't know why it's SO difficult... Of course if you know something about this I'll be just here :) ...THANKS!
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

Yes, it's me again :) (jaja...) And... yes, with a new question again :) ...Well, as you should know, I am treating to transmit all poins position info from current frame (even if there is not keyframe) to another frame (zero frame in this case) in real time, well, but now I wonder if don't will be simply impossible transmit this kind of info in this way... I mean, I can do it with a specific one point, but I'm not sure to can get all points info (AnimPos or fPos) and apply it to the same points in another frame... and maybe the only one way to get this is coping the current Keyframe to frame zero in real time, that is not exactly that I want (cause interpolating movement between keys would be missed) but maybe the only or most easy way to get something similar to my search... Well, this is my actual status about all this issue... :P CIAO!
User avatar
7feet
Posts: 840
Joined: Tue Aug 03, 2004 9:45 pm
Location: L.I., New Yawk.
Contact:

Post by 7feet »

Okay, these

Code: Select all

   local mesh
   local i 
Are not needed right off the bat. Defining a local variable without a value seems to be very bad form in Lua. Especially the "local i". The "i" variable in the loop will be a different variable than that one defined. Waste of typeing and memory, as loop index variables are automatically defined and not available outside the loop.

Try throwing in a "print" in the loop to see what values you are getting, like

Code: Select all

print ("point #:", i, "x:", point.x, "y:", point.y)
Then at least you can see if you are getting something useful.

And it sounds like you are trying something like "AnimVec2:GetValue()" which, yeah, really wont mean anything. Try the "print" above. See what you get. To transfer the animValue to to zero frame , you should just be able to do something like "point.fPos = point.fAnimPos:GetValue(frame)".

Or that could do something screwy... Don't have the time this second to check it out, but if you could put up your entire code as you have it, it would be easier to debug. Always happy to do it, I'm just a little confused right now.
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

...7FeEEeeEeeEeeeET!!! HAPPY YOU BE THERE! :D And THANK YOU very much for your advices! :) I know that see my "codes" must be like a very... amusing? :lol: for the real scripters here so --> :oops: Jaja... Well, it's true that all this can result a little confusing and maybe I should have explained better, so I think I going to put here part of the mail I sent to the great LM where I explain my purpose and his response for I will be always SO --> SO --> SO GrAteFuL! :) ...HURRAY FOR THE BEST CUSTOM SUPPORT IN THE WORLD!!! :D
Ramón López wrote: [...] Well, as you know (I think...), I have always wished the possibility to can change the way Moho treat Bones/Points interaction during animation works, you know, to can change between: bones deform points based on 0 frame points position or bones deform points based on current frame points position...

The case is that I really need something like this to can obtain the desired results and I've been treating to write an Embedded Script that copy current (cursor time) points position to frame 0 in real time, I mean, the script would transmit all the fAnimPos/fPos or AnimVec2 (I'm not sure yet...) info of the current frame to frame 0, all to can get frame 0 points position be always exactly the same that the position of that points in any other current frame... so bones be "deceived" and well, can "simulate" with it that the bone forces over the points change "dynamicaly" in time...

Of course, I know... all this seems like a madness, isn't? Well, but (if possible) that is precisely that I want to know before waste more time in the "scripting" works... Do you think that, if finally I could get the script works, something like this could work propertly? Or in the other hand (and as I afraid...) could result in a mess, bugged and unexpected animation results? [...]
And... :D LM wrote: [...] I think what you describe would be possible, but there is also one big problem.

First, to change the position at frame zero, you would do something like this:

Code: Select all

local pt = mesh:Point(id) 
-- the next line copies the current position back to frame 0 
pt:SetPos(pt.fAnimPos:GetValue(currentFrame), 0)
The skeleton would then work on the new point position. There is a slight problem: I'm not sure about the sequence of events. The skeleton might get applied before your script gets called. In that case, the skeleton wouldn't use the new value you set - it wouldn't know about it until the next frame. So, the skeleton might be running kind of "one frame behind".

The bigger problem is that you're over-writing the point positions at frame 0. So, when you do go back to frame zero, the points will be moved around in strange ways. To fix this, your script would need to save the original frame 0 positions, and restore them if the user ever went back to the real frame 0. This would take some work, but it seems like it could be possible.
:arrow: THANK YOU! (again :)) ...Well, I think this can clarify all the aspects, and I know that all this can sound like a little weird (I know...), but belive me if I say you that this is a very important and significant thing and the most actually for me at least...

Now the code that I have after I've received the esteemed LM help, I don't know if I'll have done something badly (thought I'm afraid yes...) but finally I have put it in the only way that I have could get no errors and "almost" get it works fine:

Code: Select all

function LayerScript(moho)

	local frame = moho.frame
	local mesh = moho:Mesh ()
	local pointCount = mesh:CountPoints ()

	if (mesh:CountPoints () < 1) or (moho.frame == 0) then
		return
	end

	-------------------------------------------------------------

	for i = 0, pointCount-1 do
		local mPoint = mesh:Point (i)
		pt = mPoint
	end

	pt:SetPos(pt.fAnimPos:GetValue(frame), 0)
end
And as I said... IT WORKS! :D I have been experimenting (not sure yet, but might not have such a problem about the "one frame behind" issue) and it's iNcReDiBLe GUYs! 8) But... ejem... of course only works for one point in the mesh :( ...So I have the same problem and dudes at this point...

Code: Select all

	for i = 0, pointCount-1 do
		local mPoint = mesh:Point (i)
		pt = mPoint
	end
This was part of another script that I've puted here to get some results cause without it the script give me an error... and seems that this code apply the changes over the last point of the mesh only, over the penultimate if I change pointCount-1 into pointCoun-2, and so... But seems not possible to me make the script works over ALL the points, so... Am I doing somethigng wrong? (I hope...) Or this is simple impossible to get in this way? I mean, if you get the value of several points how can be administrasted all this info, wouldn't be a mess? Uf... my head, is still the real mess :x , jaja... Well, I going to stop here, but if someone have some idea, or clue or something, you know... I'd be INCREDIBLY grateful :) ...THANK YOU for readme!

PS: Uf... Definitely my biggest post :roll: Mmm... SORRY! (very much :oops:)
Last edited by Rai López on Fri Feb 17, 2006 5:18 pm, edited 4 times in total.
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 8:22 am
Location: sweden
Contact:

Post by rylleman »

I'm not very sure of this but I believe you need an

Code: Select all

while (mesh:CountPoints () > 1) or  (moho.frame < 0) do
to repeat the copy process for each point until they are all copied.
Good luck!
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

...ALA! "Repeat the Copy Process" ...I had not thought it! :o I don't know if I've still entirely understand it but I'm going to try it right now! :D THANK YOU VERY MUCH!!! :D :D :D


EDIT1: :cry: :cry: :cry:
EDIT2: ...Uf, I've been trying all combinations without results until now... Anyway I knew nothing about that "While" and "Repeat" functions and now I'm investigating that line cause definitely it could be the way, so... THANKS FOR THE TIP! :D
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

:|...HEY! :) HEY!! :D HEY!!! :mrgreen: (...Get up everybody! :x ) ...I THINK IT WORKS!!! :D :D :D Oh, my god I can't belive it yet!!! REALLY! I hope don't be dreaming this time :roll: Jaja... See you guys, seems that all I should have done was this:

Code: Select all

function LayerScript(moho)

	local frame = moho.frame
	local mesh = moho:Mesh ()
	local pointCount = mesh:CountPoints ()

	if (mesh:CountPoints () < 1) or (moho.frame == 0) then
		return
	end

	-------------------------------------------------------------

	for i = 0, pointCount-1 do
		local mPoint = mesh:Point (i)
		pt = mPoint
		pt:SetPos(pt.fAnimPos:GetValue(frame), 0)
	end
end
...put the LM *magic* line of code inside the "for" function and that was all! Uf... well, now it's time to see how it can be improved and time too to confront the possible disadvantages/bugs that sure will be, but well... I'm HAPPY now! :mrgreen: ...THANK YOUe16 (or more...) TO EVERYBODY!!! :D Hope finally someday I can do animation with all this conquests! Jaja :)

PS: ...Really! I'm afraid to try it again just in case now it does't woks :-S
Last edited by Rai López on Fri Feb 17, 2006 7:29 pm, edited 1 time in total.
Post Reply