Howdy, Stranger!

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

Supported by

[open] buttons or inline script for randomized mouse clicking leading to different sound output?

edited November 2013 in OpenSesame

I am pretty new to opensesame. I did the tutorial and it was pretty helpful. But, apparently, what I want to do is more complex.

I am designing an experiment for nonhuman primates. They know how to use a touchscreen and the touches act just like mouse clicks.

I want to give them two clickable options on each trial. For example, they can choose from a red square or a blue square. I would like a different noise associated with each colored square. Something like, if they click the red square they get a "good noise" and if they pick the blue square a "bad noise."

I would also like the location of the squares to be randomized on each trial (either left/right, up/down or both).

From reading the forums, I gather there are two ways to accomplish this: either through forms or through inline coding.

Any suggestions on which is better to use?

I have questions regarding both. If I go with forms to create buttons, how can I change the button appearance?

If I use inline coding, how can I randomize the location of the squares.

Any help would be much appreciated.

Comments

  • edited September 2013

    I'm sure there are other ways to do this, but this is how I randomize my inline scripts:

    That's how the loop containing the inline script looks like. The inline script takes 'val_x', and depending on the value of x, will present a certain stimulus. For example, if you create a list containing all possible coordinates of your button, and set the loop up so that it cycles to as many different values of x for, say, 100 times at random, you can simply do something like

    x = val_x # sets x to the current loop ID

    current_trial_coordinates_xy = list_of_all_possible_coordinates_xy[x]

    Depending on how familiar you are with python, I can go into more detail if necessary.

  • edited 2:16PM

    From reading the forums, I gather there are two ways to accomplish this: either through forms or through inline coding.

    Just to elaborate a bit on Jona's response, another option would be to place your stimuli in a sketchpad, and collect responses using the touch_response plug-in.

    For the touch_response you can set both the number of columns and the number of rows to 2, which means that the display will be divided into a 2x2 grid, like so:

    1 2
    3 4
    

    So responses 1 and 2 correspond to the top of the screen, responses 1 and 3 correspond to the left, etc.

    In the block_loop you define the coordinates of the target and the distractor stimulus. In addition, you define both correct responses. We need to define two correct responses, since the 'participant' is allowed to touch, say, the entire top of the screen (so 1 and 2) rather than just the top-right (1) or top-left (2).

    image

    In the sketchpad item, you use the coordinates defined above to position the target and distractor, resulting in a script like this (depending on what kind of stimuli you use, the script will vary, of course):

    set duration 0
    draw circle [xTarget] [yTarget] 100 fill=1 color=red
    draw circle [xDist] [yDist] 100 fill=1 color=blue
    

    Finally, you add two sampler or synth items after the touch_response, one for a good response and one for a bad response. For the good response you use the following run-if statement:

    [response] = [correct1] or [response] = [correct2]

    For the bad response you use the following run-if statement:

    [response] != [correct1] and [response] != [correct2]

    Does that make sense? There are many other ways to implement this as well, but if you want to have an entirely Python-free implementation, than this might be the easiest way.

    Cheers!
    Sebastiaan

  • edited 2:16PM

    Thanks all. I will give this a try and let you know how it goes.

  • edited 2:16PM

    Brilliant, thanks Sebastiaan. This worked exactly like I wanted. Thanks so much.

  • edited 2:16PM

    Ok, I was too eager in my earlier response. This works almost exactly like I want.

    It appears that if you touch anywhere on the screen, it registers and goes to the next trial. I think this is because the entire screen is divided into 4 boxes and we set it up to register a correct response in the two boxes on the side of the item (1 and 2 for an item displayed in the top position).

    Is there a way I can limit correct responses to just the circle on the screen? In other words, if they touch a blank spot on the screen I don't want that to register as a response.

    I think I could divide the screen into more boxes using touch_response, say a 7x7 grid. But, if I do this I am not sure of the exact coordinates that the circle would have to fall into if it was in say block 27 of the matrix.

  • edited 2:16PM

    If you want to determine whether the taps were close enough, you're probably better off using a little inline_script after all. Basically, what you can do is replace the touch_response by a mouse_response. This will not map the clicks/ taps onto a grid, but simply store the coordinates. Then you insert an inline_script right after the mouse_response, with the code below in the run phase. This will test whether the tap was close enough to the target coordinates (see code comments for more details).

    from math import sqrt
    # The maximum error from the target center
    maxClickErr = 100
    # Use Pythagoras to determine the click error and set
    # the variable `correct` to 1 (correct) or 0 (incorrect)
    # depending on whether the click error is small enough.
    # Because the cursor coordinates have 0,0 at the top-left
    # and the sketchpad coordinates have 0,0 at the center,
    # we need to compensate for the display size.
    xc = self.get('width') / 2
    yc = self.get('height') / 2
    # Determine x and y error
    dx = self.get('cursor_x')- xc - self.get('xTarget')
    dy = self.get('cursor_y')- yc - self.get('yTarget')
    # Determine error
    clickErr = sqrt(dx**2 + dy**2)
    # Determine `correct` variable
    if clickErr <= maxClickErr:
        exp.set('correct', 1)
    else:
        exp.set('correct', 0)
    

    Next, you should also change the Run-if statements for the synth/ sampler items, because we now simply use the variable correct. For the good responses:

    [correct] = 1

    For the bad responses:

    [correct] = 0

    Finally, you can remove the columns named correct1 and correct2 from the block_loop, because they are not necessary anymore.

    Cheers!
    Sebastiaan

  • edited 2:16PM

    That's nifty. Also allows you to add the error/distance as another IV or DV.

  • edited 2:16PM

    Nice. This worked great. Thank you so much for your help! I am now telling all my colleagues about opensesame. So, you may see more questions from us psychologists who test nonhumans.

  • edited November 2013

    hi,
    so I am taking over this code from Darby and we are now trying to have it so that when the primates touch the black part of the screen nothing happens, we only want a response (and move to the next trial) if they touch the circle. with this code already in place how do I go about doing that. I have attempted to using mouse click but can seem to get it do anything

  • Hi Sarah,

    The code that Sebastiaan provided above, already checks whether participants' click error is small enough to count as correct (i.e., the built-in variable 'correct' gets the value 1). If the click error is larger, the response is labeled as incorrect (i.e., 'correct' gets the value 0).

    Next, you could use the square-bracket method in the Run-if statement(s) of the item(s) in your trial sequence, to make the next part of the trial dependent on the accuracy of the click (i.e., on the value of the variable 'correct').

    For more information, please see:

    Does that make sense? If you have difficulties implementing this into your experiment, please let us know what you've already tried (e.g. by providing us with your experimental script), and what part is not working.

    Best,

    Lotje

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

  • PS: You could also have a look at this previous thread:

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

  • edited January 2014

    Hi I have recently begun my PhD at the university of warwick and I'm quite new to programming / code etc. I used the above piece of code as I am developing what I hope will be a touch screen Corsi task in which participants are required to watch a block sequence and then tap this out on screen in the same order. Therefore I need opensesame to regcognise a touch response within the square and not anywhere else on screen and then log the co-ordinate of the touch. I used the above code therefore and I think I have it working, of sorts, I may need much more help later as its in its infancy, but I was just wondering if you knew, for write up / understanding purposes how exactly the code calculates acceptable distance, how far is too far in essense from the square to be considered correct?

    Thank you , Katherine.

    [Edit Sebastiaan: This question has been asked again and answered here]

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