| Reference | Downloads | Github

Code elements not defined online

I’ve programmed an experiment in builder in which certain elements of the stimuli change depending on various factors.

E.g. if a healthy food is presented the fixation cross is green, if an unhealthy food is presented the fixation cross is red.
To allow this to happen I’ve added a code component:

if Category == ‘H’:

if Category == ‘UH’:

And in the text element the color is set to $color and set every frame.

I’ve also done this with stimulus size and location, all of which work perfectly on builder.
However when I try to run online I’m receiving the error that the terms (e.g. color) aren’t defined.

Does anyone have any solutions for this?
Many thanks


I think the section on custom colours on page 3 of wakecarter’s crib sheet will help here!

I think you might need to add…

red = new util.Color([1, 0, 0]);

…to the begin experiment tab on the JS script side.

I hope that helps :slight_smile:

Oh brilliant - I’ll give that a go thanks!

N.B. This only works in code components not text and polygon.

Also, don’t set the colour on frames where it hasn’t changed. This can cause avoidable memory overloads

Unfortunately this hasn’t worked and I’m still getting the error “fixcolor not defined”.
Does anyone have any other suggestions as this is also a problem for other properties I’ve used code elements for.

Please could you paste / screenshot code components mentioning fixcolor ?


Screen Shot 2020-07-13 at 11.30.14

Do you really want to change the fixation colour on a frame by frame basis?

Your code component is set to Both when means you have no JS code. If your Begin Experiment code needs to be Both then I’d recommend splitting the code into two components and having this one as auto.

Also, I prefer to made Frame by Frame edits in a code component to avoid memory overload by setting something when it hasn’t actually changed.

I just want the colour to change on every trial dependent on the condition so it can be set every repeat.

I selected both based on the first suggestion about defining colours in the JS script side (I’m very unfamiliar with code so I’m still trying to learn when to use one and when to use another). I copied the code into the JS side too but now when I try to run the exp it just gets stuck on the “initialising experiment” screen

Since you are using fixcol in a text component, my suggestion of defining colours as variables won’t work. Try the code you have but with Auto translate.