Writing conditions to work both locally and in Pavlovia

I want to make it so that my participants only see the button components (i.e., next buttons) once they’ve completed the task within the routine. To that end, I wrote conditions for the start times of these buttons.

For my first routine, the start time condition reads “len(textbox.text) >= 3”, so that the button only appears once the participant has written more than 3 characters in a textbox. This works in PsychoPy, but, when I sync it to Pavlovia, the len() function no longer works.

For my second routine, the start time condition reads “scale.markerPos != None” so that the button only appears once the participant has interacted with the scale. Again, this works locally in PsychoPy, but, when I pilot in Pavlovia, it says that ‘None’ is undefined.

Is there a particular language that these conditions are meant to be written in, or perhaps a way to write them so that the experiment will work both locally and Pavlovia?

The issue is that code in components isn’t translated to JavaScript.

In the component put the start condition as something like “showButton” then in a code component put showButton = False in Begin Routine and the following in Each Frame

if showButton == False and len(textbox.text) >= 3:
     showButton = True

Use the same principle for the second routine.

I appreciate your response! I tried this with regular non-clickable elements, and it seems to work just fine. It’s definitely a solution for my original problem, but now I’m encountering a completely different one.

The issue that seems to be arising is with the buttons in Pavlovia. Buttons seem to really struggle on there.

I initially had “next” buttons that existed for the full length of every routine, but, on Pavlovia, a click from one routine would be treated as a click for the next routine (i.e., the mouse was “down” for long enough that it would be a click for both buttons), effectively skipping every other routine.

By changing the start times to 0.5 sec, it essentially fixed the problem, as the mouse wouldn’t be “down” for long enough to click on both. However, this looked kind of clunky and I hoped that using conditions would also delay the buttons long enough for a click to not be registered for both, but would look less clunky. This seems to not be the case. In fact, a click on the first “conditional” next button seems to skip over all of the rest of them. Do you know why this might be?

Is it that the routine is starting with something in textbox? If so, you could put textbox.text = “” as well as showButton = False in Begin Routine. You could also add “and t > 0.5” in the Each Frame code to delay the start.

The “and t > 0.5” got rid of the issue for me! Thank you!

Also, for anyone who might be looking into this later, the auto-converter on PsychoPy mistranslates “scale.markerPos != None” (in Python) to “scale.markerPos !== null” (in JS), which is incorrect. I needed to manually correct it to “scale.markerPos !== undefined” (in JS) for the code to work properly.

It might be worth just trying “if scale.markerPos” which should be true if scale.markerPos isn’t None/null/undefined.