Data Elements and their types¶
Data elements¶
Data elements are customizable data of a gameplay or community component. In Yahaha Studio (Studio), creators can customize data elements for community components through interface operations. For more advanced customization options, data elements can be managed using APIs.
Each data element is represented by its corresponding XML file. To access the XML file of a data element, in Studio select the component, enable Advanced Mode, then click the Open button next to Hierarchy.
Code samples¶
Here are code samples to control the game component Rotate. Open its XML file to check the hierarchy and one of its nodes is as follows:
</Node>
<Node active="True" type="LuaNode">
<Name>loopMode</Name>
<Label key="rotation.loopMode">Looping mode</Label>
<Hint key="rotation.loopMode.hint">Rotation No.: Set a one-off or an infinite number of rotation.
Type: Set the type of loop rotation. It can rotate in one direction or move to and fro.</Hint>
<Children>
<Field id="10" active="True" type="DropdownField">
<Name>times</Name>
<Label key="rotation.loopMode.times">Rotation No.</Label>
<Value default="1">1</Value>
<Options>
<Option value="1">
<Label key="rotation.loopMode.times.1">One time</Label>
</Option>
<Option value="2">
<Label key="rotation.loopMode.times.2">Infinite times</Label>
</Option>
</Options>
</Field>
<Field id="11" active="True" type="DropdownField">
<Name>mode</Name>
<Label key="rotation.loopMode.mode">Type</Label>
<Value default="1">1</Value>
<Options>
<Option value="1">
<Label key="rotation.loopMode.mode.1">One-way</Label>
</Option>
<Option value="2">
<Label key="rotation.loopMode.mode.2">Two-way</Label>
</Option>
</Options>
</Field>
</Children>
</Node>
Update the value of the Rotate component using the component operation method:
-- Create an empty YahahaObject and get its ID
local testObjectID = createEmpty()
-- Add the Rotate component to the new object and get its data element
local componentDataElement = addComponent(testObjectID,GameplayComponent.Rotate)
-- Get the 'loopingMode' node of the data element
local loopMode = getNode(componentDataElement , "loopMode")
-- Set the 'times' variable of the 'loopMode' node to 2, enabling a two-way rotation for the YahahaObject
updateModuleData(loopMode, LuaElementType.Dropdown, "times", 2)
Data element types¶
Enum for determining the type of the Lua element.
Property | Description |
---|---|
Float | A floating number value |
Float2 | Describes a vector in 2D spaces |
Float3 | Describes a vector in 3D spaces |
Time | Provides time resolution of no larger than 0.1 second |
Int | A whole number or integer value |
Dropdown | Allows the user to select one option from a predetermined list of options |
Radio | Allows the user to select one option from a list of options presented as radio buttons |
Checkbox | Allows the user to toggle a boolean value on or off |
Toggle | Allows the user to toggle a boolean value on or off with a more visually pleasing interface |
Button | A clickable button that triggers an event or function |
String | A string or text value |
Vfx | A visual effects file |
Model | A model asset |
Entity | An entity asset that can be placed in the scene |
Id | An ID number |
Items | An game asset that you can use to decorate the scene and interact with players. |
Custom | Allows the user to input a custom value based on specific constraints |
Bool3 | A table/list of three boolean values |
Color | A color value |
Animation | An animation asset file |
PlayableAudio | An audio file that can be played at runtime |
Icon | An image or icon element |
LuaNode | A expandable node for configuring community components. Users can click the left-facing arrow on the node to expand and access additional configuration information for a community component. |