Multi User Custom Experiments

For prototyping and testing on the same machine it is recommended to use the 3 window pane setup if using Windows 11. Can place the Vizard IDE on the left, the server top right and the client bottom right (or whichever laytout works best for you). Use windows key + Z, hover over maximize key, or click and drag windows to the top of the screen to activate.  It is also advisable to use Alt+Tab to go between the server and client if running on the same machine as this avoids moving the viewpoint.  

For server change SightLab instance to:

sightlab = sl.SightLabServer()

For client:

sightlab = sl.SightLabClient()


For both, use this code for the main experiment template (with custom code in the sightLabExperiment). Triggers to start and stop trial will be set in the GUI on the server side.  Make sure when converting single user GUI scripts that the start and end conditions are not set to "None"

def sightLabExperiment(): 

viztask.waitEvent(EXPERIMENT_START)

for trial in range(sightlab.getTrialCount()):

yield viztask.waitEvent(TRIAL_START)

yield viztask.waitEvent(TRIAL_END)

At end add this code for server:

viztask.schedule(sightlab.runServer)

viztask.schedule(sightLabExperiment)

viz.callback(viz.getEventID('ResetPosition'), sightlab.resetViewPoint)

And for client:

viztask.schedule(sightlab.runClient)

viztask.schedule(sightLabExperiment)

viz.callback(viz.getEventID('ResetPosition'), sightlab.resetViewPoint)

To check for a vizconnect condition on server:

if sightlab.getConfig() in["Desktop","Desktop Server"]:

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())

For code for Multi User SightLab 1.9 (earlier version) see this page