Millisecond Forums

Code to Randomize Stimuli per Trial

https://forums.millisecond.com/Topic35908.aspx

By Marusil2yada - 1/25/2024

Hi everyone,

I'm working on a project involving the Balloon Analogue Risk Task (BART), and I need some help with editing the code. The original task involves a red balloon that participants inflate to earn money, risking it popping. In my version, I want to introduce a twist: the balloon's color should change randomly at the start of each of the 30 trials.

I have six different balloon images and have figured out how to integrate them into the code. However, my current challenge is that the balloon's type changes with every press of the "pump up" button. I need the balloon's type (color) to remain constant throughout a single trial and only change when a new trial begins.

Could anyone guide me on how to modify the code to achieve this? I have attached the code file for reference.

Thank you in advance for your assistance!
By Dave - 1/26/2024

Marusil2yada - 1/26/2024
Hi everyone,

I'm working on a project involving the Balloon Analogue Risk Task (BART), and I need some help with editing the code. The original task involves a red balloon that participants inflate to earn money, risking it popping. In my version, I want to introduce a twist: the balloon's color should change randomly at the start of each of the 30 trials.

I have six different balloon images and have figured out how to integrate them into the code. However, my current challenge is that the balloon's type changes with every press of the "pump up" button. I need the balloon's type (color) to remain constant throughout a single trial and only change when a new trial begins.

Could anyone guide me on how to modify the code to achieve this? I have attached the code file for reference.

Thank you in advance for your assistance!

You have six balloon items. You need a <list> with item numbers 1 to 6.

<list balloonitemnumbers>
/ items = (1,2,3,4,5,6)
/ selectionmode = random
/ poolsize = 30
</list>


You need to define a variable to store the balloon item number applicable to the given round

<values>
...
/ balloonitemnumber = 1
...
</values>


and you'll want the balloon picture element to select the item this variable will hold, i.e.

<picture balloon>
/ items = ("balloon_red.jpg", "balloon_blue.jpg", "balloon_yellow.jpg", "balloon_red_shiny.jpg", "balloon_blue_shiny.jpg", "balloon_yellow_shiny.jpg")
/ position = (33%, 83%)
/ select = values.balloonitemnumber // here
/ valign = bottom
/ erase = false
/ scale = values.scalingFactor
/ size = (expressions.balloonSize, expressions.balloonSize)
</picture>


Finally, at the start of each round, sample the item number to use in the ensuing round.

<trial init>
/ ontrialbegin = [
    values.pumpcount = 0;
    values.timebefore1stpump = 0;
    values.timebeforecollectwithoutpump = 0;
    values.timebtwlastpumpandcollect =0;
    values.timebtwpumps = 0;
    values.sum_timebtwpumps = 0;
    values.mean_timebtwpumps = 0;
    values.countchoice = 0;
    values.scalingFactor = 1;
    values.balloonitemnumber = list.balloonitemnumbers.nextvalue; // pick balloon item for this round
]
...
</trial>

By Marusil2yada - 1/26/2024

Dear Dave,

Thank you so much. It works now!

Have a nice day!