Where is the definition of 'ScriptName'?

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
Peteroid
Posts: 162
Joined: Thu Aug 12, 2010 3:57 am
Location: las vegas, NV
Contact:

Where is the definition of 'ScriptName'?

Post by Peteroid »

NOT WHAT is the definition..

WHERE is DOCUMENT that has the FORMAL definition of 'ScriptName'... I'm guess it has all the other 'hidden' Script class info...
[==Peter==]
F.M.
Posts: 497
Joined: Thu Nov 04, 2004 4:29 pm
Location: Between my ears

Post by F.M. »

I have no idea how to script, but there is a moho_scripting folder that was made available by Mike cliffton the creator of the program, you will find at the scripting documentation(sticky). I hope this will help you in your endeavor!
"and then Man created god!"
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

Hi Peter,
first of all don't get into a nervous vicious circle.

ScriptName is a variable that must be defined with exactly the same name of the script you're writing. It probably would be used by the scriptinterface to index the scripts available or similar. People usually have a naming scheme where the two capital leters of the script is the initials of the creators ("GE" in my case)

Regarding to the other questions you're spawning around the forum I would try to give you a quick overview of how does it work:

There are three kind of scripts: Tools, Menu scripts and embedded scripts.
Tools: I've not looked or tried to write any so I just can point to the existing ones. It does perform a continous action until its state is left by selecting other tool. There is always a tool script running when the program is idle.
Menu scripts are one action scripts and just perform an action once it is called. Menu scripts has a function that has to be defined that checks if it is enabled.

Code: Select all

function GE_FreezePoints:IsEnabled(moho)
	local mesh = moho:Mesh()
	if (mesh == nil) then return false end
--	if (moho:CountSelectedPoints() == 0) then return false end
end
You define that function that is called by the script interface using the moho variable. I think you can call it whatever you want but the argument of that function is a moho object.

The rest of functions hae the same structure: you define it and it is called with a moho object (or better a moho class instance) as argument. From the moho clas instance you extract whatever you need.

Code: Select all

-- **************************************************

-- Provide Moho with the name of this script object

-- **************************************************



ScriptName = "GE_FreezePoints"



-- **************************************************

-- General information about this script

--Use together with freezer.lua embedded script

-- **************************************************



GE_FreezePoints = {}

GE_FreezePoints.Table = {}

function GE_FreezePoints:Name()

	return "Freeze Selected Points"

end



function GE_FreezePoints:Version()

	return "1.0"

end



function GE_FreezePoints:Description()

	return "Freezes the selected points and release the non selected points if were previously frozen."

end



function GE_FreezePoints:Creator()

	return "Genete"

end


function GE_FreezePoints:UILabel()

	return("Freeze Selected Points and Release non Selected")
end



-- **************************************************

-- The guts of this script

-- **************************************************


function GE_FreezePoints:IsEnabled(moho)
	local mesh = moho:Mesh()
	if (mesh == nil) then return false end
--	if (moho:CountSelectedPoints() == 0) then return false end
end

function GE_FreezePoints:Run(moho)
	local mesh = moho:Mesh()

	if (mesh == nil) then

		return

	end
	
	lname = moho.layer
	
	if (self.Table[lname] == nil) then
		self.Table[lname]= {}
	end

	for i = 0, mesh:CountPoints() - 1 do

		local point = mesh:Point(i)

		if (point.fSelected == true) then 
--			print ("point " .. i .. " is selected")
			if (self.Table[lname][i] == nil) then
				self.Table[lname][i] = {}
			end	
			self.Table[lname][i].x = point.fPos.x
			self.Table[lname][i].y = point.fPos.y
		end	
		if (point.fSelected == false) then 
--			print ("point " .. i .. " is not selected")
			if (self.Table[lname][i] ~= nil) then
				self.Table[lname][i] = nil
			end
		end
	end
--
	for k in self.Table do
		for i in self.Table[k] do

			node = self.Table[k][i]
			if (node ~= nil) then 
				print ("Point " .. i .. " from layer: " .. k:Name() .. " is in the table")
				print ("X = " .. node.x)
				print ("Y = " .. node.y)
			else
				print ("point " .. i .. " is NOT in the table")
			end
		end	
	end
end
Each menu script has a ::Run function that performs the magic. That's all.
As you can see with the moho instance you get lots of things: current selected layer, camera object, etc.
The thing is that you have to review all the damn moho scripting documentation so see what can be stracted from the moho class, what can be done and what is the interface to create layers, select points, add bones, change shape's style, etc.

Regarding to embedded scripts the situation is similar but the script is called everytime the time cursor is moved and the environment of the script is the laeyr where it is embedded.

Code: Select all

-- *******************************************
-- Embedded script for a vector layer
-- FREEZES THE COORDINATES OF THE POINTS THAT HAVE 
-- BEEN FROZEN PREVIOUSLY WIHT THE GE_FREEZE_POINTS SCRIPT
-- Version: 1.0
-- Created By Genete
-- Usage in combination with ge_freeze_points.lua a menu script.
-- *******************************************

function LayerScript(moho)

	local table = GE_FreezePoints.Table
	if (table == nil) then 
		print ("table")
		return
	end
	local layer = moho.layer
	if (table[layer] == nil) then 
		print("table layer")
		return
	end
	if (layer:LayerType() ~= MOHO.LT_VECTOR) then 
		print ("no vector")	
		return
	end
	mesh = moho:Mesh()
	if (mesh == nil) then 
		print ("no mesh")
		return
	end

	for i in table[layer] do
		local x = table[layer][i].x
		local y = table[layer][i].y
		if (i > mesh:CountPoints()-1) then 
			table[layer][i] = nil	
			return
		end
		mesh:Point(i).fPos:Set(x,y)
--		print ("point " .. i .. "position is " .. x .. y )
	end


end

In this example, the GE_FreezePoints.Table is accesed by the enbedded script because it was defined as global variable in the other script.

Botton line: You will never get more help from SM or LM about documentation. For them it is a double edge knife. It is a feature, attracts people to use and buy the program and it is a open door for features that people could add and that cannot be sold later as scripts because they are free once published.

Be patience and you'll enjoy a lot AS. Remember that it is animation not coding. Just code what is needed if you want but don't get loose like many of us did without doing grat animations with the current features of AS.

-G
User avatar
Peteroid
Posts: 162
Joined: Thu Aug 12, 2010 3:57 am
Location: las vegas, NV
Contact:

Post by Peteroid »

Genete,

Thanks! That gives me a lot of the info I've been looking for. And it might be enough for now to let me get what I'm trying to do accomplished.

Some of what you told me I never knew before, and it is KEY information. I list this as a great example (while discussing tool scripts):
You define that function that is called by the script interface using the moho variable. I think you can call it whatever you want but the argument of that function is a moho object.


That is GREAT to know! Now, I want you to step back... and consider how anyone could possible figure this out with no documentation and just looking at scripts that have very little comments? I DID notice they all had a different function that used 'moho'... I figured they just used 'moho' because they needed information from it. I looked through many Scripts looking for some 'commonly named' function (like Menu uses Run), but couldn't find any. In fact, I did see 'Run', and so I figure this was THE entry, and a lack of it was confusing. It is not clear from just studying Scripts that the entry program can be named anything but must have moho as a parameter (assuming I read what you said correctly).

I should put this in simpler (but programmer) terms. It would be confusing to study C code if everyone got to name main() anything they like! :)

I'm very curious. How did you learn this? If someone told you, how did THEY learn this? Who learned this FIRST... I want what HE's HAVING! LOL

Finally, I totally agree with this:
Be patience and you'll enjoy a lot AS. Remember that it is animation not coding. Just code what is needed if you want but don't get loose like many of us did without doing great animations with the current features of AS.
That's exactly what I'm doing. I was 'just animating'... found a need for something... wrote a C program that did it (I've been programming for 40+ years).. and then wanted to make a Script out of it, and be done. That was 5 days ago. Once I get this needed Script done, I go back to 'just' animating....

Although, since I do have an extensive programming and math and computer game designing background, I do tend to want to be precise... and doing things by hand makes that hard. So I will likely create Scripts at times to make life easier (might as well go with my strengths)... :)

THANKS AGAIN! :)
[==Peter==]
Post Reply