Dofile

From MaratisWiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "To every scene can be attached only one lua file. Use this command to use multiple files in your scene script. It can be used to include a common file that contains common fun...")
 
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
To every scene can be attached only one lua file.
+
{{lua-function|dofile|file}}
Use this command to use multiple files in your scene script.
+
It can be used to include a common file that contains common functions
+
or to include external third party libraries.
+
  
Example 1 : This script will add an external light effect library
+
Use this command to include additional lua files.
  
    dofile("lights/lightsfx.lua")
+
{{lua-function-param|file|local path of the lua file to include}}
 +
<br>
  
    light = getObject("Light")
+
Finding the local path :
  
 +
/scripts/main.lua' -> from here call dofile("other/additional.lua")<br>
 +
/scripts/other/additional.lua<br>
 +
 +
/scripts/something/main.lua -> from here call dofile("../other/additional.lua")<br>
 +
/scripts/other/additional.lua<br>
 +
 +
 +
'''Example :''' This script will add an external light effect library
 +
 +
    dofile("lights/lightsfx.lua")
 +
    light = getObject("Light")
 
     function onSceneUpdate()
 
     function onSceneUpdate()
 
         flickerLightEffects(light)
 
         flickerLightEffects(light)
 
     end
 
     end
 +
 +
[[Category:Lua scripting]]
 +
[[Category:Lua function]]
 +
[[Category:System]]

Latest revision as of 12:06, 6 April 2014

dofile(file)

Use this command to include additional lua files.

  • file : local path of the lua file to include


Finding the local path :

/scripts/main.lua' -> from here call dofile("other/additional.lua")
/scripts/other/additional.lua

/scripts/something/main.lua -> from here call dofile("../other/additional.lua")
/scripts/other/additional.lua


Example : This script will add an external light effect library

   dofile("lights/lightsfx.lua") 
   light = getObject("Light") 
   function onSceneUpdate()
       flickerLightEffects(light)
   end
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox