This version adds vci.state, a feature to synchronize item variables through network, and functions that are necessary to use the feature: updateAll, vci.assets.IsMine and ExportTransform(SubItem).IsMine.
function updateAll() -- This is run by all users regardless of ownership if vci.state.Get("TOGGLE") then vci.assets.SetMaterialColorFromIndex(0, Color.__new(1, 0, 0, 1)) else vci.assets.SetMaterialColorFromIndex(0, Color.__new(1, 1, 1, 1)) end end function onUse() -- The grip button local toggle = vci.state.Get("TOGGLE") vci.state.Set("TOGGLE", not toggle) end
An example that does almost the same.
TOGGLE="ITEM_UNIQUE_TOGGLE" -- This won't be unique when more than one of the same item are brought into the studio. vci.studio.shared.Bind(TOGGLE, function(value) -- Bind function is hard to use if value then vci.assets.SetMaterialColorFromIndex(0, Color.__new(1, 0, 0, 1)) else vci.assets.SetMaterialColorFromIndex(0, Color.__new(1, 1, 1, 1)) end end) function onUse() -- The grip button local value = vci.studio.shared.Get(TOGGLE) vci.studio.shared.Set(TOGGLE, not value) end
function updateAll() -- This is run by all users regardless of ownership if vci.assets.IsMine then -- The process end end -- The same as above function update() -- This occurs in the owner of the VCI (The user who spawned the VCI) -- The process end
subitem = vci.assets.GetSubItem('item_name') function updateAll() -- This is run by all users regardless of ownership if subitem.IsMine then -- This needs to be executed only on the owner of the SubItem subitem.SetPosition = Vector3.__new(1, 2, 3) end end