How to present sequentially counterbalanced videos

Hello, consider yourself warned - I’m a total newbie at this stuff, but hey everyone has to start at someplace.

I have a pair of videos that I want to counterbalance - I did so with vidPositions = [(-300,0),(300,0)] (the coordinates are the positions of the video) and then shuffle(vidPositions) for every trial. This produced the problem of the first video showing first on either the left or right side of the screen, when I would have liked the first video to always be on the left side of the screen, despite its being counterbalanced. Here’s my code:

    vidPositions = [(-300,0),(300,0)]
    # ------Prepare to start Routine "trial"-------
    # update component parameters for each repeat
    shuffle(vidPositions)
    print(type(vidPositions[0]))
    if vidPositions[0] = '(-300,0)':
        leftvideo = visual.MovieStim3(
        win=win, name='leftvideo',
        noAudio = True,
        filename=video1,
        ori=0, pos=vidPositions[0], opacity=1,
        loop=False,
        size=(640,360),
        depth=0.0,
        )
        rightvideo = visual.MovieStim3(
        win=win, name='rightvideo',
        noAudio = True,
        filename=video2,
        ori=0, pos=vidPositions[1], opacity=1,
        loop=False,
        size=(640,360),
        depth=-1.0,
        )
        else: rightvideo = visual.MovieStim3(
        win=win, name='rightvideo',
        noAudio = True,
        filename=video2,
        ori=0, pos=vidPositions[1], opacity=1,
        loop=False,
        size=(640,360),
        depth=-1.0,
        )
        leftvideo = visual.MovieStim3(
        win=win, name='leftvideo',
        noAudio = True,
        filename=video1,
        ori=0, pos=vidPositions[0], opacity=1,
        loop=False,
        size=(640,360),
        depth=0.0,
        )

I keep getting the error that vidPositions[0] in the if loop is invalid syntax. I’ve tried quotations, single quotes, but nothing avails. What can fix this?

In general, if you plan on doing things in the Coder view, you probably will want to read a general introduction to how Python works.

Both resources are free.

Specifically, you might want to look at these articles to understand what’s going on:

  • You want to compare values, and so you should use the comparison operator ==. (= is used for assigning values to variables in Python)
  • ‘(-300,0)’ is a string, because all characters enclosed in ’ or " symbols are interpreted as strings by Python. The value you want to compare to is (-300,0) - a tuple.

Having something to work on, like your experiment, is great for making learning Python meaningful. But you should probably be prepared to invest some time in getting a more general knowledge about how things work, not only focus on getting the experiment itself to run. Otherwise it could be a frustrating experience if you want to do more than what the Builder View allows.

:star: Good luck! :star:

1 Like

Thank you so much for the resources! I have taken the W3Schools tutorial, but evidently, it didn’t stick. I’m that kind of learner who likes to take things apart to understand their components, so PsychoPy is kind of difficult for me since I have to understand the components first before building it up.

Thank you also for the simple fix. :slight_smile:

1 Like

Check this 300+…Python Interview Questions