Skipping routines when condition file contains a specific value

Hello! I am facing similar problems as other users have in the past (see linked topics below) but still wasn’t able to solve mine. In my experiment, I want to display around 300 images in their order (show_image), but sometimes end this routine for a recognition test (show_test) with an intro (text_before_test).


My condition file looks like this:

What I want to achieve: skip a routine whenever its condition cell is 0 (or is empty or has any value if that’s easier to manage with PsychoPy). Currently, I am using this code in my “every frame” tab of the routine show_image (the same code in the other routines as well, but with their own column names).

if ((comicImage.toString() === "0")) {
    continueRoutine = false;

But I get the following error message:

  1. As the other questions were a couple of years old: is there a “best practice” in newer versions (2022.2.4) to skip routines based on a condition file value?
  2. If nothing has changed from older versions: My problem seems to be that I can’t manage to access the content of the cell, everything works until I reach a 0-cell. Logging helped to know that the type is a String{“”}. Could you take a look at my code component and give me a hint of what could be wrong? I read that other users included an inner loop but I don’t know if that would work for me - and in my opinion, it would be more easy/elegant if skipping based on the condition file would work :slight_smile:

Thank you in advance!!

Skipping routine based on variables in conditions file
How do I get Psychopy to IGNORE an empty cell and move to the next frame?

Hi @ann, from the error it seems like your image component is faster in requiring the comicImage then you can end the routine. Therefore, it “notices” that 0 is not a proper image file and throws the error. A workaround for this would be to fill the cells with a proper image file name, even if you don’t want to show it, and have a separate column (e.g., skip_image) that you could use to end the routine.

if (skip_image == 1) {
    continueRoutine = false;
1 Like

Hi @ajus, thank you so much for your quick reply, it worked perfectly and I would never have guessed that the error was about one component being fast.

In case anyone else is having the same problem, here is my changed condition file with a new column “skip_image” and an image file name that I don’t want to show at this point (material_check.jpg):

The new code in the “every frame” tab of my show_image routine (the same code is in the other routines, too, but with != 2 or != 3):

if (skip_image != 1) {
    continueRoutine = false;

Hi @ann, I only now noticed that you had the code you used before running “Every frame”. In that case, the solution might have been even simpler: Just copy it to “Begin routine”. This way it might be running before your image component needs its value. Despite the fact that you found a workaround now, you should still try this, because it’s a bit more parsimonious and easier to understand by just looking at it.

1 Like

Thank you for your reply @ajus, I tried your suggestion but actually still get error messages (also with different versions 0, ‘0’, “0” or without the .toString()) that resources are not found or that 0 is not an image or video. So I’ll stick to your former, really helpful suggestion but thank you for going through my answer, so kind :slight_smile:

1 Like

If this did not work, your code probably still runs AFTER your image component. This would be the case, if in your routine the code is BELOW your image component. You could right-click it to move it up and above the image component.

Thank you @ajus, all my code components are actually already on top because I had suspected this to cause the problem in the first place :slight_smile: until now it works fine with your workaround, but I still have some experimental features to add so maybe I have to ask for advice again

1 Like