Millisecond Forums

Looking for function

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

By clueless - 4/24/2019

Hi,
we have the following issue: we are setting up an experiment where four circles (“dots”) should remain the same color as long as they are not clicked on. When a circle is clicked on it should change color to a) yellow, if it is the first, third or fourth circle to be clicked, or b) navy, if it is the second circle to be clicked. We have written the following code for this.

<trial trial1>
/stimulusframes = [1= box1, dot1, box2, dot2, box3, dot3, box4, dot4]
/ontrialbegin = [
values.incorrect=0;

if (values.box1_click==0) shape.dot1.color = black;
if (values.box1_click==1 || values.box1_click==3 || values.box1_click==4) shape.dot1.color = yellow;
if (values.box1_click==2) shape.dot1.color = navy;

if (values.box2_click==0) shape.dot2.color = black;
if (values.box2_click==1 || values.box2_click==3 || values.box2_click==4) shape.dot2.color = yellow;
if (values.box2_click==2) shape.dot2.color = navy;

if (values.box3_click==0) shape.dot3.color = black;
if (values.box3_click==1 || values.box3_click==3 || values.box3_click==4) shape.dot3.color = yellow;
if (values.box3_click==2) shape.dot3.color = navy;

if (values.box4_click==0) shape.dot4.color = black;
if (values.box4_click==1 || values.box4_click==3 || values.box4_click==4) shape.dot4.color = yellow;
if (values.box4_click==2) shape.dot4.color = navy;

]
/inputdevice = mouse
/validresponse = (nexttext, box1, box2, box3, box4)
/ontrialend = [
(values.current_click=values.current_click+1);
if (values.box1_click<1 && trial.trial1.response=="box1") {values.box1_click=values.current_click}
else if (values.box2_click<1 && trial.trial1.response=="box2") {values.box2_click=values.current_click}
else if (values.box3_click<1 && trial.trial1.response=="box3") {values.box3_click=values.current_click}
else if (values.box4_click<1 && trial.trial1.response=="box4") {values.box4_click=values.current_click}
else if (values.current_click=values.current_click-1)(values.incorrect=1)]
/branch= [if (values.incorrect==1) trial.trial1]
</trial>

My question is whether there is a way to make the script more dynamic, specifically if there is a way to predefine 1, 3 and 4 to indicate yellow and 2 to be navy, so that when entering the /ontrialbegin if-statement, we can say something like “if the value is any of the values indicating yellow, then…”.
This would allow us, for example, to change the order of yellow and blue circles more easily in the beginning without having to re-write every if-statement for every circle.

Thank you very much for your help in advance.
By Dave - 4/24/2019

clueless - Thursday, April 25, 2019
Hi,
we have the following issue: we are setting up an experiment where four circles (“dots”) should remain the same color as long as they are not clicked on. When a circle is clicked on it should change color to a) yellow, if it is the first, third or fourth circle to be clicked, or b) navy, if it is the second circle to be clicked. We have written the following code for this.

<trial trial1>
/stimulusframes = [1= box1, dot1, box2, dot2, box3, dot3, box4, dot4]
/ontrialbegin = [
values.incorrect=0;

if (values.box1_click==0) shape.dot1.color = black;
if (values.box1_click==1 || values.box1_click==3 || values.box1_click==4) shape.dot1.color = yellow;
if (values.box1_click==2) shape.dot1.color = navy;

if (values.box2_click==0) shape.dot2.color = black;
if (values.box2_click==1 || values.box2_click==3 || values.box2_click==4) shape.dot2.color = yellow;
if (values.box2_click==2) shape.dot2.color = navy;

if (values.box3_click==0) shape.dot3.color = black;
if (values.box3_click==1 || values.box3_click==3 || values.box3_click==4) shape.dot3.color = yellow;
if (values.box3_click==2) shape.dot3.color = navy;

if (values.box4_click==0) shape.dot4.color = black;
if (values.box4_click==1 || values.box4_click==3 || values.box4_click==4) shape.dot4.color = yellow;
if (values.box4_click==2) shape.dot4.color = navy;

]
/inputdevice = mouse
/validresponse = (nexttext, box1, box2, box3, box4)
/ontrialend = [
(values.current_click=values.current_click+1);
if (values.box1_click<1 && trial.trial1.response=="box1") {values.box1_click=values.current_click}
else if (values.box2_click<1 && trial.trial1.response=="box2") {values.box2_click=values.current_click}
else if (values.box3_click<1 && trial.trial1.response=="box3") {values.box3_click=values.current_click}
else if (values.box4_click<1 && trial.trial1.response=="box4") {values.box4_click=values.current_click}
else if (values.current_click=values.current_click-1)(values.incorrect=1)]
/branch= [if (values.incorrect==1) trial.trial1]
</trial>

My question is whether there is a way to make the script more dynamic, specifically if there is a way to predefine 1, 3 and 4 to indicate yellow and 2 to be navy, so that when entering the /ontrialbegin if-statement, we can say something like “if the value is any of the values indicating yellow, then…”.
This would allow us, for example, to change the order of yellow and blue circles more easily in the beginning without having to re-write every if-statement for every circle.

Thank you very much for your help in advance.

You can put the colors in a <list> and select the color according to the number of clicks value.

<values>
/ current_click = 0
</values>

<block myblock>
/ trials = [1-4 = clicktrial; 5 = end]
</block>

<trial clicktrial>
/ ontrialend = [values.current_click += 1;
if (trial.clicktrial.response == "box1") {text.box1.textbgcolor = list.colors.item(values.current_click)};
if (trial.clicktrial.response == "box2") {text.box2.textbgcolor = list.colors.item(values.current_click)};
if (trial.clicktrial.response == "box3") {text.box3.textbgcolor = list.colors.item(values.current_click)};
if (trial.clicktrial.response == "box4") {text.box4.textbgcolor = list.colors.item(values.current_click)};
]
/ stimulusframes = [1=box1, box2, box3, box4]
/ inputdevice = mouse
/ validresponse = (box1, box2, box3, box4)
</trial>

<trial end>
/ stimulusframes = [1=box1, box2, box3, box4]
/ validresponse = (0)
/ trialduration = 1000
</trial>

<list colors>
/ items = (yellow, navy, yellow, yellow)
/ selectionmode = values.current_click
</list>

<text box1>
/ txbgcolor = black
/ size = (200px, 200px)
/ erase = false
/ position = (20%, 50%)
</text>

<text box2>
/ txbgcolor = black
/ size = (200px, 200px)
/ erase = false
/ position = (40%, 50%)
</text>

<text box3>
/ txbgcolor = black
/ size = (200px, 200px)
/ erase = false
/ position = (60%, 50%)
</text>

<text box4>
/ txbgcolor = black
/ size = (200px, 200px)
/ erase = false
/ position = (80%, 50%)
</text>

By clueless - 4/24/2019

Dave - Thursday, April 25, 2019
clueless - Thursday, April 25, 2019
Hi,
we have the following issue: we are setting up an experiment where four circles (“dots”) should remain the same color as long as they are not clicked on. When a circle is clicked on it should change color to a) yellow, if it is the first, third or fourth circle to be clicked, or b) navy, if it is the second circle to be clicked. We have written the following code for this.

<trial trial1>
/stimulusframes = [1= box1, dot1, box2, dot2, box3, dot3, box4, dot4]
/ontrialbegin = [
values.incorrect=0;

if (values.box1_click==0) shape.dot1.color = black;
if (values.box1_click==1 || values.box1_click==3 || values.box1_click==4) shape.dot1.color = yellow;
if (values.box1_click==2) shape.dot1.color = navy;

if (values.box2_click==0) shape.dot2.color = black;
if (values.box2_click==1 || values.box2_click==3 || values.box2_click==4) shape.dot2.color = yellow;
if (values.box2_click==2) shape.dot2.color = navy;

if (values.box3_click==0) shape.dot3.color = black;
if (values.box3_click==1 || values.box3_click==3 || values.box3_click==4) shape.dot3.color = yellow;
if (values.box3_click==2) shape.dot3.color = navy;

if (values.box4_click==0) shape.dot4.color = black;
if (values.box4_click==1 || values.box4_click==3 || values.box4_click==4) shape.dot4.color = yellow;
if (values.box4_click==2) shape.dot4.color = navy;

]
/inputdevice = mouse
/validresponse = (nexttext, box1, box2, box3, box4)
/ontrialend = [
(values.current_click=values.current_click+1);
if (values.box1_click<1 && trial.trial1.response=="box1") {values.box1_click=values.current_click}
else if (values.box2_click<1 && trial.trial1.response=="box2") {values.box2_click=values.current_click}
else if (values.box3_click<1 && trial.trial1.response=="box3") {values.box3_click=values.current_click}
else if (values.box4_click<1 && trial.trial1.response=="box4") {values.box4_click=values.current_click}
else if (values.current_click=values.current_click-1)(values.incorrect=1)]
/branch= [if (values.incorrect==1) trial.trial1]
</trial>

My question is whether there is a way to make the script more dynamic, specifically if there is a way to predefine 1, 3 and 4 to indicate yellow and 2 to be navy, so that when entering the /ontrialbegin if-statement, we can say something like “if the value is any of the values indicating yellow, then…”.
This would allow us, for example, to change the order of yellow and blue circles more easily in the beginning without having to re-write every if-statement for every circle.

Thank you very much for your help in advance.

You can put the colors in a <list> and select the color according to the number of clicks value.

<values>
/ current_click = 0
</values>

<block myblock>
/ trials = [1-4 = clicktrial; 5 = end]
</block>

<trial clicktrial>
/ ontrialend = [values.current_click += 1;
if (trial.clicktrial.response == "box1") {text.box1.textbgcolor = list.colors.item(values.current_click)};
if (trial.clicktrial.response == "box2") {text.box2.textbgcolor = list.colors.item(values.current_click)};
if (trial.clicktrial.response == "box3") {text.box3.textbgcolor = list.colors.item(values.current_click)};
if (trial.clicktrial.response == "box4") {text.box4.textbgcolor = list.colors.item(values.current_click)};
]
/ stimulusframes = [1=box1, box2, box3, box4]
/ inputdevice = mouse
/ validresponse = (box1, box2, box3, box4)
</trial>

<trial end>
/ stimulusframes = [1=box1, box2, box3, box4]
/ validresponse = (0)
/ trialduration = 1000
</trial>

<list colors>
/ items = (yellow, navy, yellow, yellow)
/ selectionmode = values.current_click
</list>

<text box1>
/ txbgcolor = black
/ size = (200px, 200px)
/ erase = false
/ position = (20%, 50%)
</text>

<text box2>
/ txbgcolor = black
/ size = (200px, 200px)
/ erase = false
/ position = (40%, 50%)
</text>

<text box3>
/ txbgcolor = black
/ size = (200px, 200px)
/ erase = false
/ position = (60%, 50%)
</text>

<text box4>
/ txbgcolor = black
/ size = (200px, 200px)
/ erase = false
/ position = (80%, 50%)
</text>

Thank you so much for your help, Dave! This is exactly what we were looking for!