Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

TextInput Time Limit

Hello,

I'm Trying to get text input from the user, in a set time frame (60 sec).
The Problem I'm having, is that the stopwatch is checked only after and not during the input screen.
So this loop can go beyond the time limit..

any ideas?

exp.clock.reset_stopwatch()
while exp.clock.stopwatch_time < 60000:
    list_recall.append(input_text.get())

Regards,
Ron Katz

Comments

  • edited December 2017

    I'm having the same problem with another loop,
    because of this line:

    event_id, pos, rt = exp.mouse.wait_press(buttons=0)

  • Hi Ron,

    I think the easiest way would be to register a wait callback function that checks your stopwatch time.

    def quit_after_60000ms_callback(exp):
        if exp.clock.stopwatch_time < 60000:
            return expyriment.control.CallbackQuitEvent()
    
    exp.clock.reset_stopwatch()
    expyriment.control.register_wait_callback_function(quit_after_60000ms_callback)
    
    list_recall.append(input_text.get())
    event_id, pos, rt = exp.mouse.wait_press(buttons=0)
    
    expyriment.control.unregister_wait_callback_function()
    

    Florian Krause (Developer)
    http://www.expyriment.org

  • Hi Florian,

    I wondered if the wait callback function might be the solution, but didn't know how to use it.
    Thanks a lot! That's very helpful

  • edited December 2017

    Sorry, I'm having trouble implementing it.

    I want to collect multiple inputs from the user (words he recalls), and add them to list_recall, one by one.
    I want time to act as a limit, and not the amount of words the user recalls.
    I need the whole process to last 60 seconds.
    So if I use input_text.get() in a loop, would it limit every step to 60 seconds, or the whole loop?

    def recall_time_limit(exp):
    if exp.clock.stopwatch_time < 60000:
    return expyriment.control.CallbackQuitEvent()

    exp.clock.reset_stopwatch()
    expyriment.control.register_wait_callback_function(recall_time_limit)

    while exp.clock.stopwatch_time < 60000: #?
    list_recall.append(input_text.get())

    expyriment.control.unregister_wait_callback_function()

    The Error I'm getting:

    TypeError: recall_time_limit() missing 1 required positional argument: 'exp'

    Process finished with exit code 1

  • Sorry, when defining the callback function, skip the exp argument:

    def quit_after_60000ms_callback():
        if exp.clock.stopwatch_time < 60000:
            return expyriment.control.CallbackQuitEvent()
    

    Florian Krause (Developer)
    http://www.expyriment.org

  • Hi,

    I'm Still Having an Error:

    TypeError: 'CallbackQuitEvent' object is not iterable

    Process finished with exit code 1

  • That is correct, you cannot iterate over this object. Why do you want to do this? Can you send me the code?

    Florian Krause (Developer)
    http://www.expyriment.org

  • Hi Ron and Florian,

    were you able to solve this problem? I am struggling with the exact same issue.

    I want my participants to type a word in every trial, so I would need to iterate over the time limit.

    Thank you,
    Randi

  • Hi Randi,

    I thought is was solved. My code above does not work? Can you send me your code and the full traceback of the error?

    Florian Krause (Developer)
    http://www.expyriment.org

Sign In or Register to comment.