Howdy, Stranger!

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

Supported by

Coding a loop

Hi Everybody,

I have tried different ways to do the following using the usual commands of OS but it looks tedious and tricky because this small routine does not fit the original scope of OpenSesame.
I guess it would be more effective to create an in-line script. Unfortunaltely, I don't master Python. Can you help me ? This is the structure of the routine in "natural" language:

do :

  • display "black screen"
  • wait until a keypress (y or n or esc)
  • if key = y, display "YES" (during a set time)
  • if key = n, display "NO" (during a set time)
    loop if key <> esc

"black screen", "YES" and "NO" are scketchpads.

To sum up, this routine allows a continuous monitoring of the Y/N choices of the user.
Nothing else ...

Thank you in advance !

Comments

  • edited February 14

    Hi,

    To learn python, check out some resources on our website. Or anywhere on the web, really.... It is totally worth the time investment. The future you will be very grateful.

    In theory, what you describe can also be done with sketchpad`s. You just have to make sure that you have enough repeats in your sequence and make use of the run-if statement of the items in the sequence.

    However, you are right in the sense that using Python, setting this up is a little more straightforward.

    here a little example. It is not tested, so it might not work out of the box.

    cv1 = Canvas()
    cv2 = Canvas()
    cv1.text('yes')
    cv2.text('no')
    
    kb = Keyboard()
    while True: 
         k,t = kb.get_key()
         if k!=None:
             if k=='y':
                  cv1.show()
             elif k=='n':
                  cv2.show()
             elif k == 'q':
                  break
    

    Good luck,

    Eduard

Sign In or Register to comment.