Howdy, Stranger!

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

Supported by

[solved] OSWeb break if loop

edited December 2020 in OSWeb

I'm trying to code an experiment for OSWeb where a 50-interation loop is broken if the participant presses the 'space' key.

I have used inline java script to create a breaking_variable that is true if 'space' is pressed. I have set the 'break if' function to [breaking_variable]=yes. On my desktop - this works perfectly and the loop is broken if the space key is pressed.

But, when I test the experiment online through OSWeb this does not work and I cannot find a way to break the loop. I've tried many different methods and it appears that conditionals don't seem to work on OSWeb with my code.

Is there a way I can break the loop using inline java script or without using a conditional?

Many thanks for your help,

Alex

Comments

  • Hi @agmitchell ,


    Break-if statements should work in (the latest versions of) OSWeb. Is it possible to share your experiment here, by pressing the paperclip icon, so that we can have a closer look?


    Cheers,


    Lotje

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

  • Hi again,


    What if you type "space" instead of "SPACE"? Does that solve it?


    Cheers,


    Lotje

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

  • Thanks for getting back to me. I've tried capitalizing the key presses but that doesn't work. I've also tried changing the key that's pressed, using a mouse click instead, setting the loop to repeat if keypress != space. It appears to me that it's the conditional that doesn't work - as I've double checked and the keypress is registered correctly.

    I've attached my experiment. It's the first 'screen' loop I'm having trouble with.

    Thanks


  • edited December 2020

    Hi @agmitchell ,


    It seems easier to evaluate the value of the built-in variable "response" in the break-if statement:


    • Add one line to your inline_javascript item to give the variable "response" a starting value:
    vars.response = "None"
    


    • Use the following formulation in the break-if box (no quotation marks around the word space):
    [response] = space
    


    I attached the updated experiment.


    Hope this helps!


    Cheers,


    Lotje


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

  • This worked perfectly, thank you!

  • Ahh, great to hear @agmitchell !

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

  • Hi @lvanderlinden I'm afraid I'm having this problem again. I downloaded your version of the code and everything was working perfectly. I piloted the experiment and realised I needed to change something. Changed it in OS, updated the experiment and now I'm having the same problem with the space key for the screen size form. Instead of moving on, it just 'scrolls' down the page instead.


    I've attached the experiment and was wondering if you could help me figure it out again.


  • Just FYI I solved this problem by getting participants to move on by pressing 'y' and not 'space'

  • Hi @agmitchell ,


    Ahh, great! I think an alternative would have been to use your own code again, where you were checking for both "space" and "SPACE". (Perhaps it had something to do with the capitalization...)


    Cheers,


    Lotje

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

Sign In or Register to comment.