I am building an experiment showing various text-based stimuli. I noticed that if I toggle save onset/offset times ‘on’, my logfile gets cluttered with messages about the ‘height’ attribute (see below).
I have added a code component that sets autolog to turn off, but I would still like to save onset times for the actual text stimulus shown (also see below).
Is there any way I can just call the text (i.e. “XXX_answer: text” and “XXX_answer: autoDraw = True”) without cluttering my logfile by adding height three times?
To achieve this, in the Begin Routine tab of your Code Component, you can try add the following:
def log_text_stimulus(stimulus):
logging.exp(f"{stimulus.name}: text = '{stimulus.text}'")
logging.exp(f"{stimulus.name}: autoDraw = {stimulus.autoDraw}")
log_text_stimulus(first_answer)
log_text_stimulus(second_answer)
log_text_stimulus(third_answer)
# ... Continue for other stimuli as needed
With this approach, the function log_text_stimulus will probably ensure that only the desired attributes (text and autoDraw) are logged for each text stimulus.
thank you very much for your reply! I had found a solution for the text in the meantime, but weren’t able to log the autoDraw times. Your code works in that regard, but I think it just logs the current state of autoDraw and not the actual times that autoDraw is flipped from True to False. Do you maybe have an idea on how to tackle this as well?
Thank you for pointing that out. The current code logs the status of autoDraw, not the onset times. To capture these times, consider tracking the previous state of each stimulus autoDraw. By checking this state in each frame and logging any changes with a timestamp, you’ll have an accurate record. Try to insert the following snippet into the ‘Each Frame’ tab of your Code Component. This will log the exact moment each stimulus changes its display status.
# Assuming previous states are initialized to False at the start
try:
previous_states
except NameError:
previous_states = {
'first_answer': False,
'second_answer': False,
# ... Add other stimuli names here ...
}
def check_and_log_autoDraw(stimulus):
if stimulus.autoDraw != previous_states[stimulus.name]:
# Logging the time and new state of autoDraw
logging.exp(f"{stimulus.name}: autoDraw changed to {stimulus.autoDraw} at {globalClock.getTime()}")
# Update the previous state
previous_states[stimulus.name] = stimulus.autoDraw
check_and_log_autoDraw(first_answer)
check_and_log_autoDraw(second_answer)
check_and_log_autoDraw(third_answer)
# ... Continue for other stimuli as needed ...
This approach may log the exact times when autoDraw changes state for each stimulus, giving you a clear picture of when each stimulus starts and stops being drawn.