Millisecond Forums

Conditional statements and captions

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

By psych101 - 8/7/2019

Hello,

I would appreciate any help with a couple of questions about changing the presentation on the screen based on conditional statements.

First, how could I conditionally change the colour of a caption, if a certain value (trialtype == 1) is met?

Under surveypages, I tried the following:
if (values.trialtype == 1) {
values.player_c = "you"; 
caption.c.txcolor = red}

This did not work as it did for the text in the forum response here: https://www.millisecond.com/forums/Topic16701.aspx

Is there any way to get around this?

In addition, I want to create a caption on the surveypage that only occurs if trialtype ==1 is met. Would I approach this the same way as I did above?

Thank you
By Dave - 8/7/2019

psych101 - 8/7/2019
Hello,

I would appreciate any help with a couple of questions about changing the presentation on the screen based on conditional statements.

First, how could I conditionally change the colour of a caption, if a certain value (trialtype == 1) is met?

Under surveypages, I tried the following:
if (values.trialtype == 1) {
values.player_c = "you"; 
caption.c.txcolor = red}

This did not work as it did for the text in the forum response here: https://www.millisecond.com/forums/Topic16701.aspx

Is there any way to get around this?

In addition, I want to create a caption on the surveypage that only occurs if trialtype ==1 is met. Would I approach this the same way as I did above?

Thank you

Changing the color is not possible with captions. To make a caption appear or disappear conditionally, manipulate its position.

<caption mycaption>
/ caption = "Bla"
/ position = (values.x, values.y)
</caption>

<list trialtypes>
/ items = (1,1,0,0)
</list>

<values>
/ trialtype = 0
/ x = -10%
/ y = -10%
</values>

<surveypage mypage>
/ ontrialbegin = [
values.trialtype = list.trialtypes.nextvalue;
]
/ ontrialbegin = [
if (values.trialtype == 1) {
values.x = 40%;
values.y = 10%;
} else {
values.x = -10%;
values.y = -10%;
}
]
/ questions = [1=mycaption]
/ showpagenumbers = false
/ showquestionnumbers = false
</surveypage>

<block myblock>
/ trials = [1-4 = mypage]
</block>

Theoretically, you can use the same position-trick above to get your color-change effect. I.e. if trialtype is 1, move a caption with /txcolor = red on-screen (move it off-screen otherwise), if trialtype is not 1, move a different caption with /txcolor = black on-screen (move it off otherwise).
By psych101 - 8/7/2019

Thanks, Dave! This worked for both the cases I needed help with.