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 2019

    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

    Buy Me A Coffee

  • Hi Eduard,

    Thank you very much for your help !
    Your routine works fine. I just have to adapt it to the context of the experiment.

    Best regards,
    Gérard

  • Hi Eduard,

    I have taken your advise and built a similar sequence using sketchpads and it works fine with keyboard entries. But I cannot work it out with mouse clics. The only differences in the sequence are the entry device and of course the corresponding conditional statements of the sequence. It looks like the program operates in the mouse entry step (clicks are visible) but that it does not continue in the sequence after a click. It continues to accept other clicks. It is difficult for me to provide more information because I am not allowed to upload screen captures. I have encountered the same problem when I tried to build other sequences. The mouse entry block does not work. Any advise or questions ?

    Thank you in advance!
    Gérard

  • Hi Gérard,

    Mouse items work a little differently than Keyboard items. If you check out the documentation, you will see that the mouse item returns three things: which button was clicked (left, right), the position of the click (x,y) and the timestamp of the click. A keyboard item on the other hand, returns only two things, the key and the timestamp. So the script that I wrote catches both key and timestamp (in the variables k and t) and breaks the loop once a key has been pressed.

    However, unless you have three mouse buttons you can't use the same logic, because you need a third button to exit the loop. To solve it, you have 2 options (that I can think of). First, you can define buttons on the screen, that do certain things (check out the mouse trap plugin). Second, you can add some complex logic to the loop. For example the script below, will interpret 2 right clicks in a row as the break-the-loop-signal.

    state = 'none'
    while True: 
         button,position,time = mouse.get_click()
         if button!=None:
             if button=='left':
                  cv1.show()
                  state = 'left'
             elif button=='right':
                  cv2.show()
                  if state == 'right':
                      break
                  state = 'right'
    

    Does this make sense?

    Eduard

    Buy Me A Coffee

  • Hi Eduard,

    Thank you for this interesting information based on using an inline_script. But I am stuck at a lower level because I am not able to work out this very simple sequence that I have to describe in detail for your understanding (uploads of screenshots are prohibited).

    The structure of that test program is:
    Main experiment -> Main sequence -> Loop -> 'Display' sequence.

    Parameters of the Loop:
    Execute 'Display', repeat each cycle 1 time, order sequential, source table, exit never, evaluate on 1st cycle, do not restart after the pause. The table is empty.

    The 'Display' sequence contains 4 items:
    'Black screen' sketchpad -> 'Rep' mouse_response item -> 'Yes' sketchpad -> 'No' sketchpad.

    Parameters of the 'Rep' mouse_response item :
    Correct response 'left_button', valid responses 'left_button;right_button, max delay infinite, no sketchpad is linked, event mouseclick, show the cursor, delete previous clicks.

    Conditions assigned to the items of the 'Display' sequence:
    'Black screen' : always; 'Rep' : always; 'Yes' : [response_Rep]= "left_button"; 'No' : [response_Rep] = "right_button"

    It does not work ... Nothing happens when you click. The 'Yes' and 'No' sketchpads do not show up.

    But if I replace the mouse_response item with a keyboard_response item and that I adapt the conditions attached to the 'Display' sequence according to the keys used to activate 'Yes' and 'No', it works.

    So what ?!

    Thank you very much for your time,
    Gérard

  • Hi Eduard,

    I discovered that the cause of the problem is that the mouse button names (left_button, right_button ...) that are referenced in the OpenSesame documentation DO NOT WORK. Instead, it is necessary to use the button numbers 1, 2, 3 ... The problem is solved. Thank you again for your help.

    Best,
    Gérard

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games