Lua Scripting for SimLab Training Builder

SimLab Composer’s Training Builder uses Lua scripting language. Our API allows users to create Lua scripts for their specific needs, making the tool a dynamic platform for creativity and innovation.

For Advanced Users

Lua scripting in SimLab Training Builder enables advanced users to create complex, feature-rich experiences beyond default capabilities. It allows precise customization of training scenarios with unique functionalities for immersive outcomes, offering limitless creativity.

A Proper License

Lua Scripting is only available in the Ultimate edition of SimLab Composer 12.1 or later and is not included in SimLab VR Studio.

The ‘Run Script’ Node

To execute a Lua script in SimLab Training Builder, create a ‘Run Script’ node graph by right-clicking and selecting ‘Run Script’. This node allows Lua script input and must be linked into your graph execution flow.

The print Function

The print("Hello World!") function is crucial for script writing and testing in Lua. It tracks data flow and variable states, aids in issue identification, and acts as a simple logging system for debugging and understanding code behavior.

Key Syntax Rules in Lua Programming

  • Case sensitivity: Lua is a case-sensitive language. This means that Variable, variable, and VARIABLE are all considered different identifiers in Lua.
  • Termination: In Lua, it’s not necessary to use a ; at the end of each statement.
  • Commenting: To comment out a single line, place -- at the start of the line. For commenting out multiple lines, start with --[[ on the first line and end with ]] on the final line.
  • Array Indexing: In Lua, the convention is to start arrays with an index of 1. However, you can technically start an array at index 0, 1, or any other value. But if you stick to the convention of starting arrays with index 1, you will be able to use Lua’s libraries directly. So, while it’s possible to start an array at index 0, it’s generally more convenient to start at index 1.

Caution: Lua Scripting and SimLab VR Viewer Stability

Please be aware that improper use of Lua scripting can lead to unexpected crashes in SimLab VR Viewer. Always test your scripts thoroughly before running them in production. If you encounter consistent crashes, consider reaching out to the SimLab community or support for assistance. Your understanding and caution are appreciated. Happy scripting!

Lua Scripting Tutorials: From Beginner to Beyond

  1. Beginner: Jump in to execute your initial script in a step-by-step manner.
  2. Intermediate: Retrieve weather information and reflect it in an experience.
  3. Advanced: Create a Flask server.

Links to Relative External Resources:

USimLabLuaManager

Represents a Lua Manager for SimLab VR Viewer.

new USimLabLuaManager()
Instance Members
FindNodesByName(InNodeName)
FindNodesByAttribute(AttributeName)
FindSequencesByName(InSequenceName)
FindSceneStatesByName(InSceneStateName)
OpenVRPackage(Path)
ImportVRPackage(InPathOrUrl, InTransform)
GetVariableByName(VariableName)
GetFirstPlayerController()
NewHttpRequest()
NewJsonObject()
NewJsonValue()
print(LogToPrint)

ASimLab3DObjectNode

Represents a 3D Object Node in Lua.

new ASimLab3DObjectNode()
Instance Members
GetMaterial()
SetMaterial(NewMaterial)

ASimLab3DSoundNode

Represents a 3D Sound Node in Lua.

new ASimLab3DSoundNode()
Instance Members
ToggleState()
Play()
Stop()
Seek(InTime)
PlayDuration(InDuration)

ASimLabController

Represents a Player Controller (The object that's used to control the player's character) in Lua.

new ASimLabController()
Instance Members
GetCameraTransform()
GetAttributeValue(AttributeName)
PointToNode(InNewNode)
RemovePointToNode()
TeleportToView(InEyePosition, View)
TeleportToLocation(InEyePosition)

USimLabLuaHttpRequest

Represents a Lua HTTP Request in Lua.

new USimLabLuaHttpRequest()
Instance Members
SetRequestBody(JsonBody)
ProcessRequest()
AddHeader(FieldName, StringValue)
SetEndpoint(InEndpoint)
SetVerb(InRequestVerb)
GetResponse()
Events
FOnLuaHttpRequestResponse

USimLabLuaJsonObject

Represents a JSON Object in Lua.

new USimLabLuaJsonObject()
Instance Members
SetStringField(FieldName, Value)
SetNumberField(FieldName, Value)
SetBoolField(FieldName, Value)
SetObjectField(FieldName, Value)
SetArrayField(FieldName, Value)
GetStringField(FieldName)
GetNumberField(FieldName)
GetBoolField(FieldName)
GetObjectField(FieldName)
GetArrayField(FieldName)
ToString()

USimLabLuaJsonValue

Represents a Lua JSON Value in Lua.

new USimLabLuaJsonValue()
Instance Members
AsNumber()
AsString()
AsBool()
AsArray()
AsObject()
SetString(InValue)
SetNumber(InValue)
SetBool(InValue)
SetArray(InValue)
SetObject(InValue)

ASimLabMaterial

Represents a Material in SimLab VR Viewer.

new ASimLabMaterial()
Instance Members
GetMaterialName()
GetMaterialType()
SetMaterialColor(NewColor)
GetMaterialColor()
SetMaterialAlpha(Value)
GetMaterialAlpha()

ASimLabSceneState

Represents a Scene State in SimLab VR Viewer.

new ASimLabSceneState()

Extends ASimLabAnimationSequence

Instance Members
SetDensity(Density)
GetDensity()
SetFriction(Friction)
GetFriction()
SetRestitution(Restitution)
GetRestitution()
GetSceneStateName()
Apply()

ASimLabQuizNode

Represents a Quiz in SimLab VR Viewer.

new ASimLabQuizNode()
Instance Members
ActivateQuiz()

ASimLabAnimationSequence

Represents an Animation Sequence in SimLab VR Viewer.

new ASimLabAnimationSequence()
Instance Members
GetSequenceName()
SetIsLooping(bLoop)
IsLooping()
SetIsSwinging(bSwing)
IsSwinging()
SetPlayRate(NewRate)
GetPlayRate()
GetFullRangeStartFrame()
GetFullRangeEndFrame()
SetPlayRange(StartFrame, EndFrame)
GetPlayRangeStartFrame()
GetPlayRangeEndFrame()
PlayFromStart()
Play()
Continue()
Reverse()
ReverseFromEnd()
Flip()
Stop()
Seek(Frame)
IsPlaying()
IsReversing()

ASimLabTransformNode

Represents a Scene Node in SimLab VR Viewer.

new ASimLabTransformNode()
Instance Members
GetParentNode()
GetInitialParentNode()
SetParentNode(InParent, InAttachRules)
ResetToInitialParentNode(InAttachRules)
GetChildrenNodes()
GetAncestorNodes(bIncludingMe)
GetNodeName()
GetNodeAttribute(InName)
GetNodeAttributeFromCategory(InName, InCategory)
SetNodeAttribute(InName, InValue)
SetNodeAttributeInCategory(InName, InValue, InCategory)
NodeHasAttribute(InName)
NodeHasAttributeInCategory(InName, InCategory)
SetNodeGlowState(bIsGlow)
GlowNode()
StopGlowNode()
IsNodeGlowing()
SetNodeVisibility(bInVisible)
IsNodeVisible()
ShowNode()
HideNode()
DeleteNode()
CloneNode()
GetNodeGlobalTransform()
GetNodeLocalTransform()
GetInitialGlobalTransform()
SetNodeGlobalTransform(InTransform)
SetNodeLocalTransform(InTransform)
AnimatedSetNodeGlobalTransform(ToTransform, InPlayDurationSeconds)
AnimatedSetNodeLocalTransform(ToTransform, InPlayDurationSeconds)
GetNodeGlobalLocation()
GetNodeLocalLocation()
SetNodeGlobalLocation(InLocation)
SetNodeLocalLocation(InLocation)
FallToSurface()
AnimatedFallToSurface(InPlayDurationSeconds)
AnimatedSetNodeGlobalLocation(InLocation, InPlayDurationSeconds)
AnimatedSetNodeLocalLocation(InLocation, InPlayDurationSeconds)
GetNodeGlobalRotation()
GetNodeLocalRotation()
SetNodeGlobalRotation(InRotation)
SetNodeLocalRotation(InRotation)
ResetOrientation(InType)
AnimatedSetNodeGlobalRotation(InRotation, InPlayDurationSeconds, bInShortestPath)
AnimatedSetNodeLocalRotation(InRotation, InPlayDurationSeconds, bInShortestPath)
GetNodeGlobalScale()
GetNodeLocalScale()
SetNodeGlobalScale(InScale)
SetNodeLocalScale(InScale)
AnimatedSetNodeGlobalScale(InScale, InPlayDurationSeconds)
AnimatedSetNodeLocalScale(InScale, InPlayDurationSeconds)
CancelNodeGrab()
MakeNodeGrabbable(bEnable)
SetGrabbableSequence(InSequence)
ShowMessageBox(Title, Body)
IsMessageBoxShown()
HideMessageBox()
SetNodeSimulatePhysics(bInSimulate)
IsNodeSimulatingPhysics()
AlignNodeTo(OtherNode)

UEventsVariable

Represents an Events Variable in SimLab VR Viewer.

new UEventsVariable()
Instance Members
Name
TypeName
ValueFromString(InStringValue)
ValueToString()
ChangeVariableValue(NewExpression)
SetStringValue(NewValue)
SetNumberValue(NewValue)
SetNumberValue(NewValue)
SetIntegerValue(NewValue)
UpdateTimeValue()

ASimLabVideoMaterial

Represents a Video Material in SimLab VR Viewer.

new ASimLabVideoMaterial()
Instance Members
ToggleState()
Play()
Stop()
Seek(InTime)
PlayDuration(InDuration)

ASimLabVRCamera

Represents a VR Camera in SimLab VR Viewer.

new ASimLabVRCamera()
Instance Members
IsApplyOrientation()
GetTeleportLocation()
GetTeleportRotation()