====== vci.message(receive notifications) ====== Explanation of how we can use the message feature to receive notifications.\\ ** Edit 5th March: Fixed in ver1.9.0a update. ** ** Edit 2nd February: There is a bug that sends duplicated notification when there are multiple players in a studio. This will be fixed in the near future. ** ---- ===== Show join-leave notifications on the VCI console ===== function onMessage(sender, name, message) if message == 'joined' then Print(sender.name..’joined the room.') elseif message == 'left' then Print(sender.name..’left the room.') end end vci.message.On('notification', onMessage) ==== Content of the argument when a notification is received ==== ^ Argument ^ Content ^ | sender["name"] | User name | | sender["type"] | "notification" | | sender["commentSource"] | empty string | | name | "notification" | | message | Content of the notification | ---- ==== Types of notifications ==== ^ Content ^ Description ^ | joined | Notified on join | | left | Notified on leave | ===== Example ===== A board that shows join notifications. {{ :vci:script:reference:notificationboard.zip |Notification board}} print("Notification board v1.0") -- Number of rows local lineSize = 12 -- Text array local arr = {} -- Initialize the array for i = 1, lineSize do arr[i] = "" end -- Add text function addText(text) -- Shift the position of the text for i = 0, lineSize - 2 do arr[lineSize-i] = arr[lineSize-i-1] end -- Shift the latest text to the top arr[1] = text -- Synthesize the text for i = 2, lineSize do text = text..'\n'..arr[i] end -- Display the text vci.assets._ALL_SetText("Text", text) end -- Receive notification function onMessage(sender, name, message) local text if message == 'joined' then text = sender.name..'joined the room.' elseif message == 'left' then text = sender.name..'left the room.' end print(text) if vci.assets.IsMine then addText(text) end end -- Subscribe the notification vci.message.On('notification', onMessage) -- Dummy notification for testing function test() for i = 1, 50 do local sender = { name='Test'..i } local message = 'joined' if i % 2 == 0 then message = 'left' end onMessage(sender, 'notification', message) end end -- Run the test code test()