Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

trying to show random images in an invisible circle

Hello,


I want to randomly present 6 photos from two different lists in an invisible circle at equal distance from each other, but the code does not work. Can you help me find what the error is and fix it?


Experiment is attached.


Thanks in advance,

Beril


Comments

  • Hi @bssengul,

    I'm no expert in Python but I had a lok at your task and did a few searches. The error message in the console should help you track the issue (it even indicates what line contains the problematic code. (Also, to confirm it, you can remove code and inserting it back progressively to identify what line generates the error exactly)

    Ifg you check the error message, you'll see that the issue is with this line of code:

     var.x1, var.y1 = var.img1
    

    This generates the following error:

    Traceback (most recent call last):

     File "<circle.prepare>", line 15, in <module>

    ValueError: too many values to unpack (expected 2)

    If you look up the meaning of this error on the internet, you'll find that this error comes up when is due to the function xy_from_polar returning more than two values. In Python, when you write var.x1, var.y1 = var.img1, it expects var.img1 to be a sequence of exactly two items. The error "too many values to unpack" implies that the var.img1 contains more than two items. Now, the thing is that if you check what var.img1 contains it by printing it to the console, you'll see that it actually does contain 2 elements, so the error Python generates does not provide an accurate description in this case. I suspect that it has to do with the way Open Sesame handles things, addind some layer of procesing on top of Python when it comes to handling variables.

    The good news is that playing around a little reveales a simple fix. Just replace:

    var.img1 = xy_from_polar(var.imgDist, var.imgAng1)
    var.x1, var.y1 = var.img1
    

    by:

    var.x1, var.y1 = xy_from_polar(var.imgDist, var.imgAng1)
    

    You'd have to do the same with img2 to img6. This method not only simplifies your code but also helps to avoid any confusion about variable assignments.

    You'll then have to push the images onto the canvas before you show it. Because your circle.show() command is the last event in the task, you won't actually see anything (the task will end at the same time as the canvas is displayed). So you need to add something afterwards (e.g., a keyboard response event). Finally, better write your Python code under the run tab than uder the prepare tab (otherwise the timing of the events in your trial will be messed up).

    Here's my edited version that solves the coding issue and displays the pictures before taking a keyboard response.

    Note taht given the size of your pictures, the x,y coordinates will need to be adapted (or the sice of your pictures), as they overlap spatially.

    Hope this helps!

    Fabrice.

    Buy Me A Coffee

  • Hi Fabrice, it was very helpful for me to understand. thank you so much!



    Beril

Sign In or Register to comment.