Stimulus won't animate on Pavlovia but runs fine on PC

I used the builder to design the experiment. I added these lines of code (with “Each frame*” selected) to make the two circles flicker

x =[10,0,10,0,0,10,0,10,10,0,10,10,10,10,0,0,10,10,10,10,10,0,0,10,10,10,10,0,0,0,10,0,0,0,0,10,0,0,0,0]
n = 10
seq = [item for item in x for i in range(n)]

if frameN > len(new) - 1:
    left_stim.setOpacity(0) 
else:
    left_stim.setOpacity(asarray(seq[frameN]))
        
if frameN > len(new) - 1:
    right_stim.setOpacity(0) 
else:
    right_stim.setOpacity(asarray(seq[frameN]))

Everything works just fine when I run the experiment on my computer. Somehow when I pilot the experiment on pavlovia the stimuli don’t flicker. I would like to know what may be going wrong. Thanks!

I am guessing something didn’t translate to javascript and you see /* Syntax Error: Fix Python code */ in the right hand side of your code component. There seem to be two things causing issues here

  1. using for loops in the way you have there doesn’t translate smoothly, try using nested loops instead
  2. for some reason using the variable name new prevents translation - it must be a special javascript word - what does new correspond to? can you use something else?

Thanks,
Becca

Hi,

Thanks for the helpful answer.

I believe that you’re correct and it is related to translating to javascript. I removed all mentions of ‘new’ and it didn’t work. I then tried commenting out parts of the code, and it seems like the list comprehensions are generating the error, as you suggested. I should be able to resolve this with your helpful suggestions.

I made sure the code doesn’t generate an error when autotranslating to JS but somehow the stimulus still won’t animate.

Does frameN automatically increment locally but not online?

Seems like this is what is happening, yes.

I fixed the part with the list comprehension, all that remains is

seq = [10,0,10,0,0,10,0,10,10,0,10,10,10,10,0,0,10,10,10,10,10,0,0,10,10,10,10,0,0,0,10,0,0,0,0,10,0,0,0,0]
n = 10

seq2 = [0,10,0,10,10,0,10,0,0,10,0,0,0,0,10,10,0,0,0,0,0,10,10,0,0,0,0,10,10,10,0,10,10,10,10,0,10,10,10,10]

if frameN > len(seq) - 1:
flicker_left.setOpacity(0)
else:
flicker_left.setOpacity(seq[frameN])

if frameN > len(seq2) - 1:
flicker_right.setOpacity(0)
else:
flicker_right.setOpacity(seq2[frameN])

Also – I’m not sure what the following code means so I don’t know if the auto translate knows either.
seq = [item for item in x for i in range(n)]

I just tried it and it gives a syntax error as @Becca indicated.

@wakecarter I responded to this above. I removed list comprehensions. There are no errors related to translating the code to JS anymore.

However, the stimulus is still static, so I’m not sure what is going on.

1 Like

Do you know why this might be the case? It seems like frameN is not incrementing online, and thus the stimulus is static, you are correct.

I mentioned that there were no errors associated with auto-translating the python code to JS but this problem (“stimulus not animated on Pavlovia but looks fine on my PC”) still persists. Please let me know if you have any further suggestions. Thanks.

Add frameN += 1 to Each Frame (in a JS code component only if frameN works offline) and try again. You’ll need to put frameN=0 (or -1) in Begin Routine

I will need some assistance with this. I don’t know where in the JS code to add this since I don’t know JS or the specifics of psychopy. I tried a few things but it didn’t work. The relevant part of the script is:

    // *flicker_left* updates
    if (t >= 0.0 && flicker_left.status === PsychoJS.Status.NOT_STARTED) {
      // keep track of start time/frame for later
      flicker_left.tStart = t;  // (not accounting for frame time here)
      flicker_left.frameNStart = frameN;  // exact frame index
      
      flicker_left.setAutoDraw(true);
    }

    
    // *flicker_right* updates
    if (t >= 0.0 && flicker_right.status === PsychoJS.Status.NOT_STARTED) {
      // keep track of start time/frame for later
      flicker_right.tStart = t;  // (not accounting for frame time here)
      flicker_right.frameNStart = frameN;  // exact frame index
      
      flicker_right.setAutoDraw(true);
    }

    
    // *crosshair* updates
    if (t >= 0.0 && crosshair.status === PsychoJS.Status.NOT_STARTED) {
      // keep track of start time/frame for later
      crosshair.tStart = t;  // (not accounting for frame time here)
      crosshair.frameNStart = frameN;  // exact frame index
      
      crosshair.setAutoDraw(true);
    }

    seq = [10, 0, 10, 0, 0, 10, 0, 10, 10, 0, 10, 10, 10, 10, 0, 0, 10, 10, 10, 10, 10, 0, 0, 10, 10, 10, 10, 0, 0, 0, 10, 0, 0, 0, 0, 10, 0, 0, 0, 0];
    n = 10;
    seq2 = [0, 10, 0, 10, 10, 0, 10, 0, 0, 10, 0, 0, 0, 0, 10, 10, 0, 0, 0, 0, 0, 10, 10, 0, 0, 0, 0, 10, 10, 10, 0, 10, 10, 10, 10, 0, 10, 10, 10, 10];

    if ((frameN > (seq.length - 1))) {
        flicker_left.setOpacity(0);
    } else {
        flicker_left.setOpacity(seq[frameN]);
    }
    if ((frameN > (seq2.length - 1))) {
        flicker_right.setOpacity(0);
    } else {
        flicker_right.setOpacity(seq2[frameN]);
    }

If you happen to have an answer please let me know. Thanks.

The first thing to do is step away from the compiled JS code.

In 99% of cases, edits to online experiments should be made in Builder, and most of those should be done by writing Python in Auto translate code components.

Please have a look at my crib sheet for details of how to translate Python code to JS.