Scripting: Dynamic Properties
The Dynamic properties provides you with a powerful interface for rapidly customising your script at editor or run time. Simply put, a variable can be represented by a variety of gui controls on the objects property panel. This panel can be designed how you would like to see it with your own image and heading, no more boring looking properties. Think of it as a “mod” for your script.
For example, you have a character with a move forward speed. Now imagine if you need to make your character move faster or slower! Generally this would mean you would have to open the script editor, locate the move speed variable and make a change, save the script then go back to the scene!
Mod my Object
With a dynamic property you only need to click on the character, go to its Dynamic properties tab then this would show any available variable as easy to adjust gui controls, no script and no save.
These changes are automatically saved to the object, in this case our character which would then be saved with your scene. A cool thing about this is that you can then duplicate your character and change the move speed by this property. There by having two characters moving at different speeds without any extra scripting. Reusable objects! Without any need to touch code ;)
Note: If you want to sell DLC for the game objects collection you will need to use these dynamic properties to provide your users with a pain free customization path.
Just thought to mention that if you set up these properties in a certain way you can even change an objects script value at run time! Look through some of the example scripts provided with Skylines System/library/Scripts/Example folder
Example Property Types:
To create your own set of Dynamic Properties for your Lua script you need to add some special commands to the top of your script. There are various parameter types you can use to design the way you want the Dynamic properties to look and feel.
--[[HeaderImage|myImage.png]] --[[Prop|Header]] MyHeading = “” --[[Prop|bool]] Active_CheckBox = "false"
Number Spinners for both
--[[Prop|int]] TargetID = -1 --[[Prop|float]] Run_Speed = 50.0
--[[Prop|slider]] Slider_Test = "40@0|500" [Value @ minValue | MaxValue] --[[Prop|string]] Mesh_Name = "Cube_Normal" --[[Prop|file#*.ogg]] File_Dialog_Test = "mySound"
Combo box – This has a few special qualifiers to fill the content with specific types that are available in your scene.
--[[Prop|combo#name]] ObjectNames = ”None” --[[Prop|combo#tag]] TagNames = "None" --[[Prop|combo#path]] pathNames = "None" --[[Prop|combo#custom]] comboDemo = "0@none|AI|Character|Flying" [selectIndex @ none | item1 | item2 | item3]
Push buttons – These require a special code to tell Lua which function to call when pressed.
--[[Prop|button#goup]] Goup = "Up" --[[Prop|button#godown]]Godown = "Down" function goup( id ) --do something end function godown( id ) --do something end
Setup Dynamic Values
To get the contents from this objects Dynamic Properties we use a special command:myProperty = entity.getDynamicProperty(objID, “PropertyName”)
--[[HeaderImage|myImage.png]] --[[Prop|Header#255,255,255]] ButtonExamples = "" --[[Prop|bool]] systemActive = "false" --[[Prop|label]] currentMode = "engaged" --[[Prop|float]] runSpeed = 50 --[[Prop|int]] targetID = -1 --[[Prop|string]] meshName = "Cube_Normal" --[[Prop|button#goup]] Goup = "Up" --[[Prop|button#godown]] Godown = "Down" --[[Prop|Header]] ComboExamples = "" --[[Prop|combo#path]] pathName = "None" --[[Prop|combo#path]] comboTester1 = "None" --[[Prop|combo#name]] comboTester2 = "None" --[[Prop|combo#tag]] comboTester3 = "None" --[[Prop|combo#custom]] comboTester4 = "0@none|AI|Character|Flying" --[[Prop|Header]] SliderExample = "" --[[Prop|slider]] sliderTest = "40@0|500" --[[Prop|Header]] FileExamples = "" --[[Prop|file]] fileTest = "mesh" function Setup_DynamicValues( id ) systemActive = tonumber(entity.getDynamicProperty(id, "systemActive")); runSpeed = tonumber(entity.getDynamicProperty(id, "runSpeed")); walkSpeed = tonumber(entity.getDynamicProperty(id, "walkSpeed")); targetID = tonumber(entity.getDynamicProperty(id, "targetID")); meshName = entity.getDynamicProperty(id, "meshName"); pathName = entity.getDynamicProperty(id, "pathName"); comboTester1 = entity.getDynamicProperty(id, "comboTester1"); comboTester2 = entity.getDynamicProperty(id, "comboTester2"); comboTester3 = entity.getDynamicProperty(id, "comboTester3"); comboTester4 = entity.getDynamicProperty(id, "comboTester4"); sliderTest = tonumber(entity.getDynamicProperty(id, "sliderTest")); fileTest = entity.getDynamicProperty(id, "fileTest"); sky.lprint("fileTest: "..fileTest); entity.setDynamicProperty(id, "currentMode", "engaged"); entity.refreshDynamicProperties(); end function onInit(objID) obj = objID; Setup_DynamicValues(obj); end function goup( id ) --do something end function godown( id ) --do something end function Editor_pushButton() sky.lprint("pressing editor button"); end