How to code to get a random time for the fixation cross?

Hello Soma

insert a code-component before/above the text-component.

In the Begin Experiment tab of the code-component, insert

textColorTimer = core.Clock()
timerStarted = False

in the Begin routine tab insert

text.color = 'olive'
if not timerStarted:
    textColorTimer = core.Clock()
    timerStarted = True

In the Each frame tab insert

timerRunning = textColorTimer.getTime()

if timerRunning > 3:
    text.color = 'red'
    timerStarted = False

Notice that I called my text-component text. Your is called textPoem. So you need to change the code such that it fits your component-names.

Best wishes Jens

Dear JensBoelte,

Thank you so much for your help. But what I did is:

In the Begin routine tab:

timer = core.Clock()
textPoem.color = ‘presentColor’

in the Each Frame tab:

if timer.getTime() >= 3:
textPoem.color = ‘newColor’

and it worked.

I have not entered any code to the Begin Experiment tab.

Is it okay?

Also, for time randomization (3.5 secs to 4.5 secs) of the fixation cross, I used the following code components. Please advise if it is correct as well.

In the Begin Experiment tab:

Fixation cross duration

fixDurMin = 3.5 # minimum: 3.5sec
fixDurMax = 4.5 # maximum: 4.5sec

In the Begin Routine tab:

Fixation cross duration for this trial

fixDur = np.random.uniform(fixDurMin, fixDurMax) # random between minimum and maximum
thisExp.addData(‘fixation_duration’,fixDur) # document the duration in your logfile

Am I correct? Please advise. Many thanks for your help.

With regards,
Soma

Hello Soma,

cool that you found a solution yourself. BTW, it is best to surround code with a triple `, then it is properly formatted.

With regard to your rand fixation duration. I don’t see a reason why it shouldn’t offline. I am not sure that it would online. It looks like you are importing a python-library which does not work online. Given that you draw only one value each time, uniform is not really needed. I use the following code to generate a random number from an interval

fixDur = random()*(4.5-3.5)+3.5

Best wishes Jens

Hi JensBoelte,

Thank you so much for your kind help and support.

I would like to know that if I want to change again the colour of my text, will this code work? That time would it be from “olive” to “newColor1” and “red” to “newColor2”? Or, shall I need to change from the scratch?

With best wishes,
Soma

Hello Soma,

I am sorry. I do not understand what you want?

Best wishes Jens