en:vci:script:reference:exportvci

vci(ExportVci)

You can access various information and functions in VCI.


List of member variables and functions

For the complete list, refer to “types.lua” file in “EmbeddedScriptWorkspace” folder.

---vci module
---@class ExportVci
---@field StartCoroutine fun(coroutine: usertype)
---@field studio ExportStudio
---@field me ExportMe
---@field assets ExportAssets
---@field state ExportState
---@field message ExportMessage
---@field ResetRootTransform fun()
---@field _ALL_ResetRootTransform fun()
Method Description VC version
StartCoroutine fun(coroutine: usertype) Start a coroutine 1.9.2a and later
studio
me
assets
state
message
ResetRootTransform fun() Reset the Transform of the VCI 1.9.2a and later
_ALL_ResetRootTransform fun() Reset the Transform of the VCI 1.9.2a and later

Start a coroutine

VC version: 1.9.2a and later

By using coroutine feature in lua, you can implement a Unity like coroutine in your script.

Example

main.lua
vci.StartCoroutine(
    coroutine.create(
        function()
            print("Coroutine start")
            local i = 0
            while i < 10 do
                -- Counts
                print(i)
                i = i + 1
                -- Sleep for 0.5 seconds
                sleep(0.5)
            end
            print("Coroutine end")
        end
    )
)
 
function sleep(sec)
    local t0 = os.time() + sec
    while os.time() < t0 do
        -- Stop the coroutine
        coroutine.yield()
    end
end

You can run multiple coroutines in parallel, but be careful not to run too many as it may make the system unstable.

Also, watch out for infinite loops. If the loop contains `coroutine.yield` , then it should be a problem. However, if `coroutine.yield` is not included in the loop, the error Too Many Instructions will be displayed and the script will be stopped.

Example data

This example uses multiple coroutines to animate.

coroutinesample.zip

main.lua
local cube = vci.assets.GetSubItem("Cube")
 
vci.StartCoroutine(
    coroutine.create(
        function()
            print("Coroutine1: start")
            while true do
                local r = math.random()
                local g = math.random()
                local b = math.random()
                vci.assets.SetMaterialColorFromIndex(0, Color.__new(r,g,b))
                sleep(2)
            end
        end
    )
)
 
vci.StartCoroutine(
    coroutine.create(
        function()
            print("Coroutine2: start")
            local ry = 0
            while true do
                cube.SetLocalRotation(Quaternion.Euler(0, ry, 0))
                ry = ry + 1
                coroutine.yield()
            end
        end
    )
)
 
vci.StartCoroutine(
    coroutine.create(
        function()
            print("Coroutine3: start")
            local cnt = 0
            while true do
                local x = 2 * math.cos(cnt / 100)
                local z = 2 * math.sin(cnt / 100)
                cube.SetLocalPosition(Vector3.__new(x, 4, z))
                cnt = cnt + 1
                coroutine.yield()
            end
        end
    )
)
 
function sleep(sec)
    local t0 = os.time() + sec
    while os.time() < t0 do
        coroutine.yield()
    end
end

Reset the Transform of VCI

VC version: 1.9.2a and later

Under a usual situation, item VCIs are spawned right in the front of the avatar. After the generation, calling ResetRootTransform will reset the transform of the root of the VCI. The coordinate will be set to the origin, and the rotation will also be reset.

Example

main.lua
vci.ResetRootTransform()
en/vci/script/reference/exportvci.txt · Last modified: 2020/04/17 14:42 by h-eguchi

Page Tools