Howdy, Stranger!

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

Supported by

[open] Custom forms with sound: A play it again button

edited March 2015 in OpenSesame

Hi,

Another question on custom forms.

I have created a custom form with an inline python script. While the form is displayed a sound is played (soundname fetched from surrounding loop item):

my_sampler = sampler(exp, exp.get_file('path'+ sound +'.wav'))
my_sampler.play()

This works, but I would like to add a button to the form that plays the same sound again if it is clicked and without proceeding to the next item in the sequence.

How can I do this?

Best,

Johannes

Comments

  • edited 2:10PM

    Hi Johannes,

    I just answered your previous question, and I think the same strategy can be applied for this one.
    Hence, you place the form in a loop sequence together with the item that plays your sound, and for the sound item insert a run-if command so that it is only played if a certain variable is set to True (or whatever you want of course), and then insert code so that that variable is in fact set to True only when your button is pressed.

    Good luck, let me know if you encounter any problem!

    Cheers,

    Josh

  • Hi,
    I've got a similar question.
    I have a form with 3 buttons: Button1 and button2 are supposed to start a sampler, while button3 is an "ok" button that leads to the next form.
    I placed the forms and the sampler items in a loop sequence as suggested here and inserted run-if commands as shown in the screenshot.

    The problem is that when either of the first two buttons is pressed the experiment moves on to the main experimental loop, jumping over the rest of this sequence AND the practice loop sequence that should follow (the sound is played correctly shortly before that, however).
    But I want my participants to be able to click on each of the buttons (ideally as often as they wish), listen to the sound played and only move on to the next form when they click on the "ok" button.

    Any ideas on how this can be achieved?

    Cheers,
    Sophia

  • edited August 2017

    I got a bit further with the buttons, but still have a problem.
    I deleted the loop (which I didn't really use sensibly anyway) and just left the forms and samplers in a sequence.

    The sequence looks like that now:

    define sequence welcome_sequence
        set flush_keyboard yes
        set description "Runs a number of items in sequence"
        run welcome_screen always
        run example_screen always
        run example_long "[button1] = yes"
        run example_short "[button2] = yes"
        run example2_screen always
        run example_sp "[button4] = yes"
    

    I set the sampler duration to "mouseclick" which helped a bit. When participants click on button1 now, the correct sound is played and the form is still displayed. But the cursor isn't displayed anymore so one cannot click on button2 as the next mouseclick now leads to the following form.

    How can I make the cursor visible?
    I found this Python command in the mouse description:

    function mouse.show_cursor(show=True)
    

    Is there an equivalent in OpenSesame scripting that can be used with forms? Or (how) can I use this here? I've never done any inline scripting.

    Cheers!

  • Hi,

    This requires some scripting, but should be doable . First, you need to create the form that has all the buttons you need. Put it somewhere in the experiment. It doesn't really matter where, but set its run if statement to never.
    Next, put an inline_script in your experimental sequence, with following code.

    # load sound 1
    src = pool['bark.ogg']
    sampler1 = sampler(src, volume=.5)
    
    # load sound 2
    src2 = pool['bark2.ogg']
    sampler2 = sampler(src, volume=.5)
    
    while True: 
        items.execute(u'your_form')
        if response_variable == 'sound1_button': # whatever the sound1 button response variable is
            sampler.play()
        elif response_variable == 'sound2_button': # whatever the sound2 button response variable is
            sampler2.play()
        elif response_variable == 'ok_button': # whatever the ok button response variable is
            break
        # do something to kill time while the sound is played (optional)
    

    Good luck,

    Eduard

    Buy Me A Coffee

  • edited August 2017

    Hi Eduard,

    Thank you very much for your advice and script!
    Running it, I got an error (that is probably due to my lack of knowledge on how Python works).
    The error message is:

    exception message: name 'response_variable' is not defined

    The code for my form is as follows (the var=xy following the pattern described on the Creating custom forms page):

    set timeout infinite
    set spacing 10
    set rows "2;1;1;1;1;1;1;1;1;1"
    set only_render no
    set margins "50;50;5;50"
    __form_text2__
    bla
    __end__
    __form_text1__
    blabla
    __end__
    set cols "1;1;1;1;1"
    set _theme gray
    widget 0 0 5 1 label center=no text="[form_text1]"
    widget 2 1 1 1 button text=listen var=button1
    widget 0 4 5 1 label center=no text="[form_text2]"
    widget 2 5 1 1 button text=listen var=button2
    widget 4 8 1 1 button text=next var=ok_button
    

    And the script you wrote looks like this after my adaptation:

    # load sound 1
    src = pool['Slip_fb1.wav']
    example_long = sampler(src, volume=.5)
    
    # load sound 2
    src2 = pool['rOp_fb4.wav']
    example_short = sampler(src, volume=.5)
    
    while True: 
        items.execute(u'example_screen')
        if response_variable == 'button1': # whatever the sound1 button response variable is
            example_long.play()
        elif response_variable == 'button2': # whatever the sound2 button response variable is
            example_short.play()
        elif response_variable == 'ok_button': # whatever the ok button response variable is
            break
        # do something to kill time while the sound is played (optional)
    

    So I guess the problem is that var and response_variable don't match. But if I replace response_variable with var in the inline script, giving

    while True: 
            items.execute(u'example_screen')
            if var == 'button1': # whatever the sound1 button response variable is
                example_long.play()
            elif var == 'button2': # whatever the sound2 button response variable is
                example_short.play()
            elif var == 'ok_button': # whatever the ok button response variable is
                break
    

    then none of the buttons can be pressed and the form is just displayed forever.
    How can I define the variable?

    Thanks!

  • Ok, I figured it out in the end. Thanks again to Eduard for getting me there!
    In case anyone else should get the same problem, here's the code for the inline script that worked:

    # load sound 1
    src = pool['sound1.wav']
    example_long = sampler(src, volume=1)
    
    # load sound 2
    src2 = pool['sound2.wav']
    example_short = sampler(src2, volume=1)
    
    while True: 
        items.execute(u'example_screen')
        if var.button1== 'yes' : 
            example_long.play()
        elif var.button2 == 'yes' : 
            example_short.play()
        elif var.ok_button== 'yes' : 
            break
    

    Took me a while to try out "yes" in a Python script... ;)

    Cheers,
    Sophia

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