Dynamically change text color based on


Dynamically change text color based on

Author
Message
Lingi
Lingi
Associate Member
Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)

Group: Forum Members
Posts: 6, Visits: 23
Hi everyone,
I would like to dynamically change the textcolor via expressions as I do for the text that is presented - but this does not work.
Does anybody know whether there is a bug in my script or if there is any other way to dynamically change the textcolor of an element depending on conditions?
Thank you for your help!

<text newTaskReminder>
/ items = ("<%expressions.new_task_reminder%>")
/ position = (50%, 80%)
/ txcolor = <%expressions.newTaskReminderColor%>
/ size = (80%, 6%)
/ fontstyle = ("Arial", 3%, false, false, false, false, 5, 1)
</text>

<expressions>
/new_task_reminder={
if(values.targetTask == values.taskA) {
"BUCHSTABE ~n '<%text.letter.#ff2e50%>' ~n'<%parameters.leftKeyLabel%>': <%expressions.letter_left%>              '<%parameters.rightKeyLabel%>': <%expressions.letter_right%>";
} else if (values.targetTask == values.taskB) {
"ZAHL ~n '<%text.number.#ff2e50%>' ~n'<%parameters.leftKeyLabel%>': <%expressions.number_left%>              '<%parameters.rightKeyLabel%>': <%expressions.number_right%>";
} else {
"?????????";
}
}

/newTaskReminderColor={
if(values.targetTask == values.taskA) {
darkmagenta;
} else if (values.targetTask == values.taskB) {
limegreen;
} else {
orangered;
}
}

</expressions>
Dave
Dave
Supreme Being
Supreme Being (447K reputation)Supreme Being (447K reputation)Supreme Being (447K reputation)Supreme Being (447K reputation)Supreme Being (447K reputation)Supreme Being (447K reputation)Supreme Being (447K reputation)Supreme Being (447K reputation)Supreme Being (447K reputation)

Group: Administrators
Posts: 9K, Visits: 38K
Lingi - Tuesday, April 3, 2018
Hi everyone,
I would like to dynamically change the textcolor via expressions as I do for the text that is presented - but this does not work.
Does anybody know whether there is a bug in my script or if there is any other way to dynamically change the textcolor of an element depending on conditions?
Thank you for your help!

<text newTaskReminder>
/ items = ("<%expressions.new_task_reminder%>")
/ position = (50%, 80%)
/ txcolor = <%expressions.newTaskReminderColor%>
/ size = (80%, 6%)
/ fontstyle = ("Arial", 3%, false, false, false, false, 5, 1)
</text>

<expressions>
/new_task_reminder={
if(values.targetTask == values.taskA) {
"BUCHSTABE ~n '<%text.letter.#ff2e50%>' ~n'<%parameters.leftKeyLabel%>': <%expressions.letter_left%>              '<%parameters.rightKeyLabel%>': <%expressions.letter_right%>";
} else if (values.targetTask == values.taskB) {
"ZAHL ~n '<%text.number.#ff2e50%>' ~n'<%parameters.leftKeyLabel%>': <%expressions.number_left%>              '<%parameters.rightKeyLabel%>': <%expressions.number_right%>";
} else {
"?????????";
}
}

/newTaskReminderColor={
if(values.targetTask == values.taskA) {
darkmagenta;
} else if (values.targetTask == values.taskB) {
limegreen;
} else {
orangered;
}
}

</expressions>


<text newTaskReminder>
/ items = ("<%expressions.new_task_reminder%>")
/ position = (50%, 80%)
/ txcolor = <%expressions.newTaskReminderColor%>
/ size = (80%, 6%)
/ fontstyle = ("Arial", 3%, false, false, false, false, 5, 1)
</text>

This is invalid syntax / the /txcolor attribute does not work like that. What you need to do is set the <text> element's textcolor property in your <expressions> directly, as in

<expressions>
/newTaskReminderColor = if(values.targetTask == values.taskA) {
text.newTaskReminder.textcolor = darkmagenta;
} else if (values.targetTask == values.taskB) {
text.newTaskReminder.textcolor = limegreen;
} else {
text.newTaskReminder.textcolor = orangered;
}
</expressions>

<values>
/ targetTask = 1
/ taskA = 1
/ taskB = 2
</values>

<block myblock>
/ trials = [1=mytrial]
</block>

<trial mytrial>
/ stimulusframes = [1=newTaskReminder]
/ validresponse = (57)
</trial>

<text newTaskReminder>
/ onprepare = [
    expressions.newTaskReminderColor;
]

/ items = ("Some text....")
/ position = (50%, 80%)
/ size = (80%, 6%)
/ fontstyle = ("Arial", 3%, false, false, false, false, 5, 1)
</text>

Edited
4 Months Ago by Dave
Lingi
Lingi
Associate Member
Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)Associate Member (152 reputation)

Group: Forum Members
Posts: 6, Visits: 23
This worked as inteded! Thank you very much for your quick and competent help!

GO


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....






Millisecond Forums


Search