INTRODUCTION AND UPDATES
==============================================
I created this thread to showcase template scripts to help people new to the Anime Studio API. Before you go dive into the templates, I'd suggest using these websites to help ease your transition into Anime Studio and LUA.
ANIME STUDIO API: http://www.animestudioscripting.com/
ONLINE LUA IDE(use this to practice LUA): http://repl.it/languages
A LUA TUTORIAL SERIES: https://www.youtube.com/playlist?list=P ... ctmMOJ70t_
If anyone wants to donate template code, send it to me and I'll toss it up and credit you.

==============================================
TEMPLATE ONE:
TYPE: TOOL
AS VERSION: 10
DESC: BASIC BUTTON MENU WITH NESTED BOX BUTTON
==============================================
Code: Select all
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "dr_testtool"
-- **************************************************
-- General information about this script
-- **************************************************
dr_testtool = {} --Make certain that this table name is the SAME as the ScriptName Above!!!
dr_testtool.BASE_STR = 5285 --This value is used for language localization. If that means nothing to you, then ignore it.
function dr_testtool:Name() --This will display the name of your script
return "testval"
end
function dr_testtool:Version()
return "0.1"
end
function dr_testtool:Description() -- This sets the description that shows up below the header bar
return MOHO.Localize("/Scripts/Tool/testval/Description= REPLACE THIS SENTENCE WITH WHAT YOU WANT TO SAY!")
end
function dr_testtool:Creator()
return "YOUR NAME GOES HERE"
end
function dr_testtool:UILabel() -- This information is displayed when the user hovers over the tool
return(MOHO.Localize("/Scripts/Tool/testval/testval=Label for Test"))
end
-- **************************************************
-- BODY OF THE SCRIPT STARTS HERE
-- **************************************************
-- **************************************************
-- PLACE TABLE TEMPLATES ('CLASS TEMPLATES' for people from other languages) HERE.
-- THESE TABLES ARE BASICALLY JUST CLASSES. THEY WILL GET ASSIGNED TO AN OBJECT IN
-- THE ACTIVE TABLE SIMILAR TO A CLASS.
-- **************************************************
local MenuTemplate = {} --CREATE A LOCAL TABLE AS A TEMPLATE FOR THE MENU BUTTON
function MenuTemplate:new() --IN THIS TABLE, WE DESIGN THE MENU.
local menu = LM.GUI.SimpleDialog(MOHO.Localize("/Scripts/Tool/testval/testval=Test Val"), MenuTemplate)
local lay = menu:GetLayout()
lay:PushV(LM.GUI.ALIGN_LEFT, 0) --# This gets popped at the end of the function
menu.testbox = LM.GUI.CheckBox(MOHO.Localize("/Scripts/Tool/testval/testbox=TEST BOX:"), dr_testtool.MenuObject_1_CHANGE) -- This buttons talks on channel "MenuObject_1_CHANGE"
lay:AddChild(menu.testbox, LM.GUI.ALIGN_LEFT)
lay:PushH(LM.GUI.ALIGN_RIGHT, 0)
lay:AddChild(LM.GUI.Button(MOHO.Localize("/Scripts/Tool/testval/Close=Close"), LM.GUI.MSG_CANCEL))
lay:Pop()
lay:Pop() --# This Pops the first PushV
return menu
end
function MenuTemplate:UpdateWidgets() --THIS IS JUST AN UPDATE TEMPLATE, IT MUST BE UPDATED BY THE 'REAL' UPDATER -> dr_testtool:UpdateWidgets()
print("UpdateWidget FUNCTION ACTIVATED")
end
function MenuTemplate:OnOK() --THIS BUTTON WILL EXECUTE EVERYTIME YOU CLOSE THE BUTTON
print("OnOK FUNCTION ACTIVATED")
end
function MenuTemplate:HandleMessage(msg) --THE HANDLEMESSAGE FUNCTION WATCHES FOR MESSAGES SENT BY BUTTONS. IF A BUTTON MATCHES ONE OF ITS CRITERIA, IT DOES STUFF.
print("HANDLEMESSAGE FUNCTION ACTIVATED.")
if (msg == dr_testtool.MenuObject_1_CHANGE) then -- MAKE SURE TO USE THE BASE TABLE WHEN CHECKING THE MESSAGE VALUE!!!!!
if (self.testbox:Value() == true) then --THIS CHECKS THE TRUE/FALSE VALUE OF THE CHECK BOX
print("BOXCHECK = " .. tostring(self.testbox:Value() ))
else
print("BOXCHECK = " .. tostring(self.testbox:Value() ))
end
end
end
-- **************************************************
-- THIS IS WHERE THE ACTIVE "MAIN" CODE EXISTS. THIS IS THE CODE THAT IS UPDATED AND DOES WORK.
-- **************************************************
function dr_testtool:DoLayout(moho, layout) --IN THIS TABLE, WE DRAW THE MENU TO THE SCREEN
--Here we create an object of the button template we defined above.
self.MenuObject_1 = MenuTemplate:new()
self.popup = LM.GUI.PopupDialog(MOHO.Localize("/Scripts/Tool/testval/testboxx=TEST BOX"), true, self.MenuObject_1_BEGIN) --Notice this buttons talks on channel "MenuObject_1_BEGIN"
self.popup:SetDialog(self.MenuObject_1)
layout:AddChild(self.popup) --This draws the button to the screen.
end
-- HERE WE DESIGNATE CHANNELS THAT THE BUTTONS WILL TALK ON. WE DON'T WANT BUTTONS TALKING ON ONE CHANNEL AT THE SAME TIME,
-- SO WE MAKE PLENTY OF CHANNELS AND WE MAKE THEM UNIQUE.
dr_testtool.CHANGE = MOHO.MSG_BASE --MOHO.MSG_BASE is a base channel number. The others will use this as a start and just offset by a number.
dr_testtool.MenuObject_1_BEGIN = MOHO.MSG_BASE + 1
dr_testtool.MenuObject_1_CHANGE = MOHO.MSG_BASE + 2
function dr_testtool:UpdateWidgets(moho) --THIS IS THE "MAIN" updatewidget. Anime Studio will update THIS widget.
self.popup:Enable(true) -- THIS ENABLES OUR MENU BUTTON
self.MenuObject_1:UpdateWidgets() -- Notice that the real widget updates the widget in MenuObject
end
function dr_testtool:HandleMessage(moho, view, msg) --THIS IS THE HANDLEMESSAGE FUNCTION FOR NON-NESTED BUTTONS.
end