Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

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

  • RonKatzRonKatz Posts: 8
    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)

  • fladdfladd Posts: 96

    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

  • RonKatzRonKatz Posts: 8
    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

  • fladdfladd Posts: 96

    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

  • fladdfladd Posts: 96

    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

Sign In or Register to comment.