Howdy, Stranger!

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

Supported by

Sequence timing

Hi!

In my current experiment I want people to be able to fill something in for 12 seconds. If they haven't filled anything in by that time, they should automatically go to the next trial.

Participants will type in a score and are able to switch between the boxes with the left and right arrow keys (the green box around the textbox indicating which one they've selected). Once they are done and rated all 3 items they can press enter and continue to the next trial themselves if they don't want to wait out the 12 seconds.

The issue here is that I've set the keyboard response timer to 12 seconds, which works if they never touch anything. However every time they click a button the loop is repeated. This means that 1 trial can basically go on forever if people just keep switching between textboxes for example.

Therefore I was wondering if there is a way to time how long a sequence (click sequence in this case) has been running, if the sequence has been running for 12 seconds, then the loop should end.

I hope you can help!

Kind regards,

Sanne


Comments

  • Hi @Sannee ,


    Sorry for not getting back to this question earlier. And yes, you did the right thing opening different threads for different questions! :)


    Could you check whether the following logic works?

    • Append two more inline_javascript items. One before starting the loop that collects the clicks, the other one at the beginning of the click sequence, like so:



    • Place something like the following in the Run tab of the first inline_javascript item:
    // Initial timeout
    vars.var_timeout = 12000 
    // Current time stamp (right before starting the click loop)
    vars.starting_time = new Date().getTime();
    // Create a variable that checks whether a timeout
    // occurred
    vars.timeout_occurred = "no"
    


    • And something like this to the second one (also in the Run tab):
    // Get current timestamp
    vars.current_time = new Date().getTime();
    // Calculate the time that is passed:
    vars.time_passed = vars.current_time - vars.starting_time
    // Update the timeout:
    vars.var_timeout = 12000 - vars.time_passed
    // Make sure that the timeout cannot be negative:
    if (vars.var_timeout <= 0){
        // Change the variable keeping track of whether
        // a timeout occurred
        vars.timeout_occurred = "yes"
        }
    console.log("time passed = " + vars.time_passed)
    


    • Use the Run-if statements to only run the remainder of the click sequence if no timeout occurred:


    • And change the Repeat-if statement in the repeat_cycle element, making sure that we break from the loop if a timeout occurred:

    [check] == no and [timeout_occurred] != "yes"


    I attached the modified script. I hope this results in the behaviour that you are looking for.


    Cheers,


    Lotje


    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Hi Lotje!

    No worries at all!

    And this indeed works exactly as I wanted it too! Such a simple solution but in all honesty I would never have found it myself. Thanks so much for your help not just on this question but all the others as well!

    Kind regards,

    Sanne

Sign In or Register to comment.