en:vci:script:module

module feature

The module feature is a feature which can call and use a program written on other files.
Like a class, you can modularize Lua script based on their functions.

  • To use the module feature, you need VCI v0.20 or later.
  • The module feature is supported on VirtualCastは1.7.0a or later.

How to set up the module (VCI Object)

  1. Size: specify a number which is “the number of modules to use +1.”
  2. Name: type the name of the module
  3. Paste the program for this module in the text field

Things to note, specs, etc.

  • You can call a module from a module(You couldn't in the past but now you can).
  • To create a module while debugging on Virtual Cast..
    leave the 3rd text area blank and upload to the SEED.\\Then edit the script from the EmbeddedScriptWorkspace folder.
  • You cannot access a function that is under the vci table (e.g., vci.assets)
  • You can use types such as Quaternion, Vector 3, etc.

Call and execute a module

main.lua
-- Store the feature of the module in module_1
local module_1 = require "module_1"
-- Call a function in module_1
print(module_1.GetName())
print(module_1.GetVector())
module_1.lua
-- Return the name of its file name
local function GetName()
    return "module_1"
end
 
-- Return Vector3.__new(0,100,0)
local function GetVector()
    return Vector3.__new(0,100,0)
end
 
-- required for using IntelliSense (predictive input) in VScode
return {
    GetName = GetName,
    GetVector = GetVector
}

Result

module_1
(0,100,0)

Use it like a class

main.lua
local module_1 = require "module_1"
local test1 = module_1.new(50,1)
local test2 = module_1.new(100,2)
test1:pp() -- You can ommit the self argument by usnig a colon. Same as "test1.pp(test1)" 
test2:pp()
module_1.lua
local module_1 = {} -- This name can be anything
module_1.new = function(_x,_y) -- create a table dynamically with the "new function"
    local obj = {}
    obj.x = _x
    obj.y = _y
 
    obj.pp = function(self) 
        print(string.format("(%d,%d)", self.x, self.y)) 
    end
    return obj 
end
 
return module_1
en/vci/script/module.txt · Last modified: 2021/06/29 19:34 by t-daihisa

Page Tools