Post by AnkuLua on Sept 21, 2015 16:02:41 GMT
AnkuLua provides some methods to make scripts more flexible.
toast(String)
toast show the String on screen shortly.
Dialog related methods
The following methods provide mechanics to get inputs from script user.
AnkuLua call the interface as dialog.
Dialog provides following elements, TextView, EditText, CheckBox, RadioGroup and RadioButton.
TextView, EditText and CheckBox are arranged horizontally in a row.
To start a new row, use newRow() method.
RadioGroup may contains many RadioButton. Only one of the radio buttons could be true at one time.
The details about the methods are described below.
dialogInit()
dialogInit() initialize a new dialog design. Every new dialog should start from this method.
addTextView(String)
addTextView add a new string to the dialog.
addEditText(String argument, String defaultValue)
addEditText will get a string input from user. The input will be assign to a new global variable argument.
addEditPassword(String argument, String defaultValue)
addEditPassword will get a string input from user. The input will be assign to a new global variable argument.
The input text is hidden as password.
addEditNumber(String argument, Integer defaultValue)
addEditNumber will get a number (integer or float number) from user. The input will be assign to a new global variable argument.
addCheckBox(String argument, String text, boolean defaultValue)
addCheckBox will create a check box with string text. The boolean value defaultValue represents the box is checked (true) or not (false).
The box check result will be assign to a new global variable argument.
newRow()
Finish previous horizontal row and create a new one.
addRadioGroup(String argument, integer defaultIndex)
This method creates a new radio group. All the following addRadioButton methods will add radio buttons to this group until next addRadioGroup.
The index of checked radio button will be assign to a new global variable argument.
addRadioButton(String text, integer index)
addRadioButton creates a new radio button with text. The integer index represents the value to radio group if the button checked.
addRelativeRadioGroup(String argument, integer defaultIndex, integer maxColumn)
This method creates a new relative radio group. addRelativeRadioGroup allows upto maxColumn columns, as addRadioGroup allows only one column.
All the following addRadioButton methods will add radio buttons to this group until next addRadioGroup.
The index of checked radio button will be assign to a new global variable argument.
addRelativeRadioGroupNewRow()
Finish previous horizontal row and begin a new one. It's useful for arranging the radio buttons.
Refer to following script about the usage of addRelativeRadioGroup() and addRelativeRadioGroupNewRow().
The result of above script.

addSpinner(String argument, Table of String, String defaultValue)
addSpinner will get a string from one of the strings in table. The input will be assign to a new global variable argument.
addSpinnerIndex(String argument, Table of String, String defaultValue)
addSpinnerIndex(String argument, Table of String, integer defaultValue)
Works just like addSpinner. The only difference is the return value. addSpinnerIndex will assign the new global variable argument with integer, not string.
addSeparator()
Add a separator. The method also finish previous horizontal row and create a new one.
dialogShow(String title)
dialogShow will show the dialog design with title from previous dialogInit till dialogShow method.
dialogShowFullScreen(String title)
The same as dialogShow(String title) except the dialog is shown in full screen (almost).
Default and preference value
As show above, default values are provided for those methods returning values.
AnkuLua provide preference mechanism for the returning values. That is, AnkuLua will remember the settings for each arguments and set them according when the dialog created next time.
Therefore, the default values are only used once when first called.
To remove the preference value, use removePreference()
removePreference(String argument)
Remove the preference value of argument.
Example
An example is provide. You can download it here.
It's also shown below.
After clicking play button, following screen is shown.

If modify the values according to below

After clicking OK, the result is

To show the effect of preference saving, click play button again.
The values show previous result.

preference
Although dialog will save the result of previous execution, but those values can only be obtained after dialog.
And for some usages not related with dialog, users can save those values with following methods.
preferencePutString(String arg, String value), preferencePutNumber(String arg, Number value), preferencePutBoolean(String arg, Boolean value)
save value to arg argument.
Return value: true (success) or false(fail)
preferenceGetString(String arg, String defValue), preferenceGetNumber(String arg, Number defValue), preferenceGetBoolean(String arg, Boolean defValue)
If arg is saved before, return the saved value. Otherwise, return defValue.
removePreference(String arg)
Remove the remembered preference value and use the default value instead when referring to the preference value next time.
Others
setButtonPosition(int x, int y)
setButtonPosition(Location loc)
Set the position of start/stop button. It could avoid the click of stop button by script.
[Next]: Advanced Methods
[Previous]: Settings
[Home]: AnkuLua Introduction
toast(String)
toast show the String on screen shortly.
Dialog related methods
The following methods provide mechanics to get inputs from script user.
AnkuLua call the interface as dialog.
Dialog provides following elements, TextView, EditText, CheckBox, RadioGroup and RadioButton.
TextView, EditText and CheckBox are arranged horizontally in a row.
To start a new row, use newRow() method.
RadioGroup may contains many RadioButton. Only one of the radio buttons could be true at one time.
The details about the methods are described below.
dialogInit()
dialogInit() initialize a new dialog design. Every new dialog should start from this method.
addTextView(String)
addTextView add a new string to the dialog.
addEditText(String argument, String defaultValue)
addEditText will get a string input from user. The input will be assign to a new global variable argument.
addEditPassword(String argument, String defaultValue)
addEditPassword will get a string input from user. The input will be assign to a new global variable argument.
The input text is hidden as password.
addEditNumber(String argument, Integer defaultValue)
addEditNumber will get a number (integer or float number) from user. The input will be assign to a new global variable argument.
addCheckBox(String argument, String text, boolean defaultValue)
addCheckBox will create a check box with string text. The boolean value defaultValue represents the box is checked (true) or not (false).
The box check result will be assign to a new global variable argument.
newRow()
Finish previous horizontal row and create a new one.
addRadioGroup(String argument, integer defaultIndex)
This method creates a new radio group. All the following addRadioButton methods will add radio buttons to this group until next addRadioGroup.
The index of checked radio button will be assign to a new global variable argument.
addRadioButton(String text, integer index)
addRadioButton creates a new radio button with text. The integer index represents the value to radio group if the button checked.
addRelativeRadioGroup(String argument, integer defaultIndex, integer maxColumn)
This method creates a new relative radio group. addRelativeRadioGroup allows upto maxColumn columns, as addRadioGroup allows only one column.
All the following addRadioButton methods will add radio buttons to this group until next addRadioGroup.
The index of checked radio button will be assign to a new global variable argument.
addRelativeRadioGroupNewRow()
Finish previous horizontal row and begin a new one. It's useful for arranging the radio buttons.
Refer to following script about the usage of addRelativeRadioGroup() and addRelativeRadioGroupNewRow().
setImmersiveMode(true)
dialogInit()
addRelativeRadioGroup("rrgIndex", 11, 3)
addRadioButton("Button 11", 11)
addRadioButton("Button 12", 12)
addRadioButton("Button 13", 13)
addRadioButton("Button 21", 21)
addRelativeRadioGroupNewRow()
addRadioButton("Button 31", 31)
addRadioButton("Button 32", 32)
addRadioButton("Button 33", 33)
addRadioButton("Button 41", 41)
addRadioButton("Button 42", 42)
addRelativeRadioGroupNewRow()
addRadioButton("Button 51", 51)
newRow()
addSeparator()
addRelativeRadioGroup("rrgIndex2", 12, 2)
addRadioButton("Button 11", 11)
addRadioButton("Button 12", 12)
addRadioButton("Button 21", 21)
addRadioButton("Button 22", 22)
addRelativeRadioGroupNewRow()
addRadioButton("Button 31", 31)
addRadioButton("Button 32", 32)
addRadioButton("Button 41", 41)
addRelativeRadioGroupNewRow()
addRadioButton("Button 51", 51)
addRelativeRadioGroupNewRow()
addRadioButton("Button 61", 61)
dialogShowFullScreen("Relative Radio Group Test")
print("rrgIndex = " .. rrgIndex)
print("rrgIndex2 = " .. rrgIndex2)
The result of above script.

addSpinner(String argument, Table of String, String defaultValue)
addSpinner will get a string from one of the strings in table. The input will be assign to a new global variable argument.
allTroops = {"barbarian", "archer", "giant", "goblin", "wallBreaker",
"balloon", "wizard", "healer", "dragon", "PEKKA" }
addSpinner("training1", allTroops, allTroops[1])
addSpinnerIndex(String argument, Table of String, String defaultValue)
addSpinnerIndex(String argument, Table of String, integer defaultValue)
Works just like addSpinner. The only difference is the return value. addSpinnerIndex will assign the new global variable argument with integer, not string.
addSeparator()
Add a separator. The method also finish previous horizontal row and create a new one.
dialogShow(String title)
dialogShow will show the dialog design with title from previous dialogInit till dialogShow method.
dialogShowFullScreen(String title)
The same as dialogShow(String title) except the dialog is shown in full screen (almost).
Default and preference value
As show above, default values are provided for those methods returning values.
AnkuLua provide preference mechanism for the returning values. That is, AnkuLua will remember the settings for each arguments and set them according when the dialog created next time.
Therefore, the default values are only used once when first called.
To remove the preference value, use removePreference()
removePreference(String argument)
Remove the preference value of argument.
Example
An example is provide. You can download it here.
It's also shown below.
removePreference("cbValue")
dialogInit()
addTextView("TextViewMessage")
addTextView("TextViewMessage")
addEditText("etValue", "Input EditText value:")
newRow()
addCheckBox("cbValue", "Check Box", false)
addRadioGroup("rgIndex", 1)
addRadioButton("Button 1", 1)
addRadioButton("Button 10", 10)
addRadioButton("Button 11", 11)
newRow()
spinnerItems = {"item 1", "item 2", "item 3", "item 4", "item 5", "item 6", "item 7"}
addTextView("Spinner: ")
addSpinner("spValue", spinnerItems, "item 3")
newRow()
spinnerItems = {"Indexitem 1", "Indexitem 2", "Indexitem 3", "Indexitem 4", "Indexitem 5", "Indexitem 6", "Indexitem 7"}
addTextView("Spinner Index: ")
addSpinnerIndex("spValueIndex", spinnerItems, "Indexitem 3")
newRow()
addTextView("Text End")
dialogShow("Dialog Test")
print(etValue)
if (cbValue) then
print ("CheckBox true")
else
print("CheckBox false")
end
toast ("Selected Button = "..rgIndex)
print ("Selected Button = "..rgIndex)
print ("spValue = " .. spValue)
print ("spValueIndex = " .. spValueIndex)
After clicking play button, following screen is shown.

If modify the values according to below

After clicking OK, the result is

To show the effect of preference saving, click play button again.
The values show previous result.

preference
Although dialog will save the result of previous execution, but those values can only be obtained after dialog.
And for some usages not related with dialog, users can save those values with following methods.
preferencePutString(String arg, String value), preferencePutNumber(String arg, Number value), preferencePutBoolean(String arg, Boolean value)
save value to arg argument.
Return value: true (success) or false(fail)
preferenceGetString(String arg, String defValue), preferenceGetNumber(String arg, Number defValue), preferenceGetBoolean(String arg, Boolean defValue)
If arg is saved before, return the saved value. Otherwise, return defValue.
print ("======= simple test ===========")
print("int_test = " .. preferenceGetNumber("int_test", 6))
preferencePutNumber("int_test", 9)
print("int_test = " .. preferenceGetNumber("int_test", 6))
print("string_test = " .. preferenceGetString("string_test", "new"))
preferencePutString("string_test", "default")
print("string_test = " .. preferenceGetString("string_test", "test"))
print("boolean = " .. tostring(preferenceGetBoolean("boolean", true)))
preferencePutBoolean("boolean", false)
print("boolean = " .. tostring(preferenceGetBoolean("boolean", false)))
removePreference(String arg)
Remove the remembered preference value and use the default value instead when referring to the preference value next time.
Others
setButtonPosition(int x, int y)
setButtonPosition(Location loc)
Set the position of start/stop button. It could avoid the click of stop button by script.
[Next]: Advanced Methods
[Previous]: Settings
[Home]: AnkuLua Introduction