The ShiVa scripting language is based on LUA and the LUA syntax. It mostly follows the LUA conventions, however there are some key differences you should be aware of.
Table of Contents
General Syntax RulesShiVa Script mostly follows the LUA conventions. We assume you have a basic understanding of programming, so this is merely a short guide to help you translate your general programming knowledge to the LUA syntax.
Instruction EndThere is no need for a Semicolon ";" in Lua after each command, even after a variable declaration, a function call, etc.
CommentsTo comment out a line, use: --
-- This line is commented
To comment a group of lines, use: --[[ ]]
--[[ This group of lines is commented ]]
Branches and LoopsBranches and Loops are used to execute code based on conditions (true or false, object existing or not, handle valid or not, object not nil, etc) as well as repeat the same code over and over if necessary. In these conditions, parentheses are not required, but it is better to write them to improve code readability.
ifif-branches follow the structure
"if (condition) then --do code elseif (condition) then --do codeelse --do code end"
Here are 3 examples of if-branching:
if ( bCondition ) then --script block end
if ( bCondition ) then --script block else --script block end
if ( bCondition ) then --script block elseif ( bCondition2 ) then --script block elseif ( bCondition3 ) then --script block end
whileThis loop runs while the condition is true and terminates as soon as the condition is false.
while ( bCondition ) do --script block end
forfor-loops are incremental and follow the general syntax
"for varInit = numberInitValue, numberIncludedLimit, numberStepping do --do code end"
Stepping is optional. If no parameter is specified, stepping is 1.
for i = 0, 5 do --script block --count i up by 1 after loop has completed end
for i = 0, 10, 3 do --script block --count i up by 3 after loop has been completed end
repeatThis loop runs if the condition is false, and terminates as soon as the condition is true.
repeat --script block until ( bCondition )
break"break" exits a loop. If used in a while loop for instance, the loop terminates even if the exit conditions are still false.
SamplesHere are some simple script examples to familiarize you with the syntax.
-- Rotating an object of 45 degrees around the global Y axis: object.rotate ( this.getObject ( ), 0, 45, 0, object.kGlobalSpace ) -- Changing the opacity of the mesh attached to an object: shape.setMeshOpacity ( this.getObject ( ), 0.5 ) -- Getting the position of a skeleton joint attached to an object: local x, y, z = shape.getSkeletonJointTranslation ( this.getObject ( ), "head", object.kGlobalSpace ) -- Playing the first sound attached to an object: sound.play ( this.getObject ( ), 0, 1, false, 0.5 ) -- Sending a message to an object: object.sendEvent ( hTargetObject, "AIModelName", "onHandlerName", ... ) -- Getting a reference on the current scene: local s = application.getCurrentUserScene ( )