Saving a script in the right format

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
F.M.
Posts: 497
Joined: Thu Nov 04, 2004 7:29 am
Location: Between my ears

Saving a script in the right format

Post by F.M. »

I am trying to modify the BoneAudioWiggle script to change stroke colors, but I can't save it in the right format, I'm using the Mac's Textedit and I don't see any options for saving in the Unix format, any thoughts on the subject would be appreciated!
"and then Man created god!"
User avatar
funksmaname
Posts: 3174
Joined: Tue May 29, 2007 3:31 am
Location: New Zealand

Post by funksmaname »

I'm not using a mac, but through previous cross browser problems it seems that Mac's don't add a file extension by default... try explicitly naming the file "whateveryouwannacallit.lua" and hopefully it will work??

D.
User avatar
heyvern
Posts: 7043
Joined: Thu Sep 01, 2005 8:49 pm

Post by heyvern »

Can you describe what you mean "can't save the right format"? What exactly isn't working? Do you get errors when using the script? Format shouldn't matter. It's just plain text. Make sure it has the .lua extension. Be sure that "display file extension" is turned on. Make sure you are saving as "plain text" and not RTF. I think text edit defaults to RTF.

I do scripting on both Mac and PC. I use a free open source text editor called "jEdit" that works the same on both platforms without any trouble. This program is great because it has syntax highlighting for lua.

-vern
F.M.
Posts: 497
Joined: Thu Nov 04, 2004 7:29 am
Location: Between my ears

Post by F.M. »

Vern, I used J edit as you suggested, saving with it worked, this is what happened next(my first attempt at scripting) I put the script in the menu folder, then launched AS and the lua console gave this message

...plications/Anime Studio Pro 7/scripts/menu/Sound/LM_strokecolorsound.lua:39: '<eof>' expected near 'end

The script doen't appear in the pull down menu. This is what the script looks like. (don't laugh now!) :lol:

Code: Select all

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

-- Provide Moho with the name of this script object

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



ScriptName = "LM_StrokeColorSound"



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

-- General information about this script

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



LM_LM_StrokeColorSound = {}



LM_LM_StrokeColorSound.BASE_STR = 2530



function LM_LM_StrokeColorSound:Name()

	return "LM_StrokeColorSound"

end 

functionLM_StrokeColorSound:Version()

	return "6.0"

end



function LM_StrokeColorSound:Description()

	return MOHO.Localize("/Scripts/Menu/StrokeColorSound/Description=Uses a sound file to control a stroke's color.")

end



function LM_StrokeColorSound:Creator()

	return "Smith Micro Software, Inc."

end



function LM_StrokeColorSound:UILabel()

	return(MOHO.Localize("/Scripts/Menu/StrokeColor/StrokeColor/AudioWiggle=StrokeColor Audio Wiggle..."))

end



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

-- Recurring values

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



 LM_StrokeColorSound.audioLayer = 0

 LM_StrokeColorSound.magnitude = 255

 LM_StrokeColorSound.stepSize = 2



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

 stroke sound dialog

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


local  LM_StrokeColorSoundDialog = {}



function  LM_StrokeColorSoundDialog:new(moho)

	local d = LM.GUI.SimpleDialog(MOHO.Localize("/Scripts/Menu/StrokeColorSound/Title=StrokeColorSound Audio Wiggle"), LM_StrokeColorSoundDialog)

	local l = d:GetLayout()



	d.moho = moho

	      l:AddChild(LM.GUI.StaticText(MOHO.Localize("/Scripts/Menu/StrokeColorSound/SelectAudioLayer=Select audio layer:")), LM.GUI.ALIGN_LEFT)

	d.menu = LM.GUI.Menu(MOHO.Localize("/Scripts/Menu/StrokeColorSound/SelectAudioLayer=Select audio layer:"))

	for i = 0, moho:CountAudioLayers() - 1 do

		local audioLayer = moho:GetAudioLayer(i)

		d.menu:AddItem(audioLayer:Name(), 0, MOHO.MSG_BASE + i)

	end

	d.menu:SetChecked(MOHO.MSG_BASE, true)



	d.popup = LM.GUI.PopupMenu(256, true)

	d.popup:SetMenu(d.menu)

	l:AddChild(d.popup)



	l:PushH(LM.GUI.ALIGN_CENTER)

		l:PushV()

			l:AddChild(LM.GUI.StaticText(MOHO.Localize("/Scripts/Menu/StrokeColorSound/MaxAngle=Max angle")), LM.GUI.ALIGN_LEFT)

			l:AddChild(LM.GUI.StaticText(MOHO.Localize("/Scripts/Menu/StrokeColorSound/FrameStep=Frame step")), LM.GUI.ALIGN_LEFT)

		l:Pop()

		l:PushV()

			d.magnitude = LM.GUI.TextControl(0, "0.0000", 0, LM.GUI.FIELD_FLOAT)

			l:AddChild(d.magnitude)

			d.stepSize = LM.GUI.TextControl(0, "0.0000", 0, LM.GUI.FIELD_UINT)

			l:AddChild(d.stepSize)

		l:Pop()

	l:Pop()



	return d

end

function LM_function LM_StrokeColorSoundDialog:UpdateWidgets()

	self.menu:SetChecked(MOHO.MSG_BASE, true)

	self.magnitude:SetValue(LM_StrokeColorSound.magnitude)

	self.stepSize:SetValue(LM_StrokeColorSound.stepSize)

end



function LM_StrokeColorSoundDialog:OnValidate()

	local b = true

	if (not self:Validate(self.magnitude, -360, 360)) then

		b = false

	end

	if (not self:Validate(self.stepSize, 1, 1000)) then

		b = false

	end

	return b

end



function LM_StrokeColorSoundDialog:OnOK()

	LM_StrokeColorSound.audioLayer = self.menu:FirstChecked()

	LM_StrokeColorSound.magnitude = self.magnitude:FloatValue()

	LM_StrokeColorSound.stepSize = self.stepSize:FloatValue()

end

Dialog:UpdateWidgets()

	self.menu:SetChecked(MOHO.MSG_BASE, true)

	self.magnitude:SetValue(LM_StrokeColorSound.magnitude)

	self.stepSize:SetValue(LM_StrokeColorSound.stepSize)

end



function LM_StrokeColorSoundDialog:OnValidate()

	local b = true

	if (not self:Validate(self.magnitude, -360, 360)) then

		b = false

	end

	if (not self:Validate(self.stepSize, 1, 1000)) then

		b = false

	end

	return b

end



function LM_StrokeColorSoundDialog:OnOK()

	LM_StrokeColorSound.audioLayer = self.menu:FirstChecked()

	LM_BoneSound.magnitude = self.magnitude:FloatValue()

	LM_StrokeColorSound.stepSize = self.stepSize:FloatValue()

end



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

-- The guts of this script

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



function LM_StrokeColorSound:IsEnabled(moho)

	if (moho:CountAudioStrokeColor() < 1) then

		return false
	end

	return true

end



function LM_StrokeColorSound:Run(moho)

	-- ask user for the angle offset magnitude

	local dlog = LM_LayerSoundDialog:new(moho)

	if (dlog:DoModal() == LM.GUI.MSG_CANCEL) then

		return

	end

	-- begin audio extraction

	local audioLayer = moho:GetAudioLayer(self.audioLayer)

	local audioDuration = audioLayer:LayerDuration() / moho.document:Fps()

	if (audioDuration <= 0) then

		return

	end



	moho.document:PrepUndo(moho.layer)

	moho.document:SetDirty()



	local frame = 1 - audioLayer:TotalTimingOffset()

	local layerTimingOffset = moho.layer:TotalTimingOffset()

	local layerFrame = frame + layerTimingOffset

	local baseOffset = moho.layer.fTranslation.value

	local newOffset = LM.Vector3:new_local()

	local audioTime = 0

	local frameDuration = self.stepSize / moho.document:Fps()



	while (audioTime < audioDuration) do

		local amp = audioLayer:GetAmplitude(audioTime, frameDuration)



		layerFrame = frame + layerTimingOffset

		if (layerFrame > 0) then

			newOffset:Set(baseOffset)

			newOffset.y = newOffset.y + amp * self.magnitude

			moho.layer.fTranslation:SetValue(layerFrame, newOffset)

		end



		audioTime = audioTime + frameDuration

		frame = frame + self.stepSize

	end

end

Last edited by F.M. on Thu Aug 26, 2010 8:07 pm, edited 2 times in total.
"and then Man created god!"
User avatar
heyvern
Posts: 7043
Joined: Thu Sep 01, 2005 8:49 pm

Post by heyvern »

The lua error you see is a result of an improper closing of a function or "if" structure. You have too many "ends" or one is in the "wrong" place. It could be the formatting got lost when you pasted your script here but it helps if you indent your code so you can see the structure.

I don't have time to find the error right now. Will try to look at it more closely later if I can.

TIP: if you paste script code in the forum use the Code button to wrap around it and it will keep the format intact for us to read it better.

-vern
F.M.
Posts: 497
Joined: Thu Nov 04, 2004 7:29 am
Location: Between my ears

Post by F.M. »

I'm sure there will be multiple errors!
"and then Man created god!"
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 7:27 am
Location: España / Spain

Post by Genete »

Code: Select all

function LM_StrokeColorSound:Run(moho)
   -- ask user for the angle offset magnitude
   local dlog = LM_LayerSoundDialog:new(moho)
   if (dlog:DoModal() == LM.GUI.MSG_CANCEL) then
      return
   end\
Maybe the "end\" is the cause? :)
-G
F.M.
Posts: 497
Joined: Thu Nov 04, 2004 7:29 am
Location: Between my ears

Post by F.M. »

Genete, I will see if removing that, will allow the script to function.

Thanks for taking time to help.
"and then Man created god!"
F.M.
Posts: 497
Joined: Thu Nov 04, 2004 7:29 am
Location: Between my ears

Post by F.M. »

I had no luck with that, It must be something more serious.
"and then Man created god!"
Post Reply