Information to determine if running online/offline

Hi all,

I was just wondering if there was any internal data or a flag which can feedback if an experiment is currently being ran offine (psychopy) or online (pavlovia) ? Something which can be accessed in code to make decisions, and which translates perfectly between both? (i.e. doesn’t have to be re-written for online).

At the moment we’re just simply using a “online” parameter at the start set to 0 or 1 to indicate, but it would be useful to have something that automatically detects - so we can decide if for instance to use an “.mp3” or .“wav” sound file accordingly without having to have separate versions of trial excel files/scripts.

What I do is use a Both code component, for example:

Python: fileName = Sound+’.wav’
JavaScript: fileName = Sound+".mp3";

Alternatively, you can just have a JS component which does a string replace of .wav to .mp3

1 Like

Thanks Wakecarter - we’re doing something similar, though were hoping to avoid two separate code segments, in case someone accidently has “auto” set on the code generation and it overwrites. If there was a flag that could be read, then ideally it would mean whatever code you write on the Python side would automatically translate to the relevant Javascript without the need for maintaining two versions.

Having “online” as a start up parameter allows us to do that to a degree, as we can essentially do:

if online == 1:
extension = “.mp3”
else:
extension = “.wav”

… which translates automatically and perfectly, then just bolt the extension onto the filename where called.

Not a critical issue, just something that would be a nice to have somewhere in in expInfo or similar that is accessible from the off.