Importing Sightlab Multi-User into Project

For importing the Multi-User Sightlab into your existing project the  process and code is similar to the single user except that you have to use a separate file for the server and client. Note, if setting up the scene in code, you will need to manually add the environment model to both the server and the client and choose "Empty" when selecting the environment from the server. 

Code for server: 

import vizimport vizfxfrom utils import sightlab_server
#Code to disable the GUI from showing (set to 1 if you want the GUI)sightlab_server.is_GUI = 1
#run sightlab experiment. Add code here to run alongside main sightlab experimentimport viztaskdef sightLabExperiment(): yield viztask.waitKeyDown(' ') print('experiment start server')
yield viztask.waitKeyDown(' ') print('experiment end server') if __name__ == '__main__':    viztask.schedule(sightlab_server.recordWithTimer)    viztask.schedule(sightLabExperiment)

For Client:

import vizimport vizfxfrom utils import sightlab_client
#Code to disable the GUI from showing (set to 1 if you want the GUI)sightlab_client.is_GUI = 1
#run sightlab experiment. Add code here to run alongside main sightlab experimentimport viztaskdef sightLabExperiment(): yield viztask.waitEvent(sightlab_client.NETWORK_KEY_EVENT) print('experiment start client') yield viztask.waitEvent(sightlab_client.NETWORK_KEY_EVENT) print('experiment end client') if __name__ == '__main__':    viztask.schedule(sightlab_client.experiment)    viztask.schedule(sightLabExperiment)

To trigger events from the server to the clients you will need to first create an event ID and then use that for the callback, similar to the following code: 

Add this to both server and client: 

import viznetdef id(name):    """Generate unique ID for use over viznet"""    return f'viznet:{name}'YOUR_EVENT = id('YOUR_EVENT')

Create function on server side: 


def doSomething(): print ('something happened')viznet.server.send(YOUR_EVENT,client=viz.net.getName())vizact.onkeydown('1',doSomething)

Create function on client side that is triggered by the event sent from the server: 


def somethingHappened(e): print('received trigger')viz.callback(YOUR_EVENT, somethingHappened) 
For sending from the client use this code:viznet.client.sendAll(SPEAK_EVENT, client=viz.net.getName())