Howdy, Stranger!

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

Supported by

Selecting random picture number-inline script

Hello,

I am creating an experiment with 20 images from 3 different categories and a total of 80 trials. Each images is called by its category and a number that goes from 1 to 20. In the sketchpad where the images have to be presented I have the following written:

draw image center = 1 file = "[category_image] [num] .jpg" scale = 1 show_if = always x = 300 y = "[DisLeft]" z_index = 0

The variable num is writen in the loop table with the numbers from 1 to 20 on each row. The problem is that I have 80 trials in total and I have to repeat the secquence 3 times to complete the rest of rows that are empty in this column [num]. Is there any code that can generates random numbers for [num] instead of taking them from a column in the loop table?

I want to keep the category column in order that the program reads all the type of images as follows in the table. I just want to randomise the number of the image.

I have seen this code on the forum but does not work:

Inline script:

import random

# select random number 
randnr = random.randint(1,20)

# store variables
exp.set("use_this_number", randnr)

Sketchpad:

draw image center = 1 file = "[category_name][use_this_number].jpg" center=1 color=[use_this_colour] font_family="mono" font_size=64 font_italic=no 


Thank you very much, I will appreciate any idea.


cheers!

Comments

  • Hi,

    the problem is probably that randnr was missing the var part. So, var.randnr = random.randint(1,21)

    should be fine. I attach also a small experiment to demonstrate the procedure.

    Does that make sense?

    Eduard

    Buy Me A Coffee


  • Hi!

    Thank you very much, it did work!!!!:D


    cheers

Sign In or Register to comment.