Howdy, Stranger!

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

Supported by

[solved] Using random values in Sketchpad

edited June 2014 in OpenSesame

Hello friendlies,

For my Bsc-thesis I'm trying to recreate an experiment using OpenSesame. It's a fairly basic experiment (I'd say), consisting of 3 different kinds of stimuli:

Ongoing Task (OT), Distractor Task (DT) and Ambiguous Task (AT). All three consist of a focus point and one digit above in case of the OT, a digit both above and below focus point in case of DT & AT. 80% of the time I'd like to present the the OT-stimuli, the other 20% is reserved for the other two. As switching between stimuli is important, I need some kind of randomness implemented. I'd expect there to be an easy way to implement such 'randomness', however, as I'm a total newbie to OpenSesame, I'm having trouble finding said way. Is this possible, without having to dive deep into the python inline?

Another randomness issue I'm having:
I found another forum post which a question related to randomness (http://forum.cogsci.nl/index.php?p=/discussion/240/solved-variable-interstimulus-interval-isi/p1) and I tried using what I could get from that in my project, where I'd like to vary both between randomly picked digits and their respective greyvalues (RGB values?).

I managed to add an inline_script element to my trial_loop, with the following piece of code (thanks to lvanderlinden):

import random

stimuli_values_set = [1,2,3,4,6,7,8,9]

use_this_number = random.choice(stimuli_values_set)

exp.set("use_this_number", use_this_number)

Then I figured, I can just call on this variable in my Sketchpad, to draw whichever number is produced by picking from that list:

draw textline 0 -192 "[use_this_number]" center=1 color=#7f7f7f font_family="mono" font_size=64 font_italic=no 

But sadly, it's not working as I'd hoped (parallel to this I would love to randomize the color of the drawn digits).

Hope both of these 'questions' aren't all that 'stupid' nor overwhelming.

Thanks alot in advance.

Regards,
daan

Comments

  • edited May 2014

    Hi Daan,

    Your approach is correct! Could it be that you have placed the code for the random number in the Run phase of an inline_script item? It should be in the Prepare phase, as this is when the sketchpad is constructed. For more info on the difference between the Run and the Prepare phase, see here.

    On your other problem, of random RGB values, just extend your script a bit:

    import random
    
    # select random number (same as your list approach)
    randnr = random.randint(1,9)
    
    # select random colours
    r = random.randint(0,255)
    g = random.randint(0,255)
    b = random.randint(0,255)
    
    # RGB to hex value
    randcol = '#%02x%02x%02x' % (r,g,b)
    
    # store variables
    exp.set("use_this_number", randnr)
    exp.set("use_this_colour", randcol)
    

    And adjust your sketchpad a bit:

    draw textline 0 -192 "[use_this_number]" center=1 color=[use_this_colour] font_family="mono" font_size=64 font_italic=no 
    

    Good luck!

    Edwin

  • edited 6:52AM

    I love how quick you guys are with your replies! And I had been wondering what that little 'Prepare' tab was for! :)

    Thanks a lot, should make things alot easier.

  • edited May 2014

    As for the 'pseudo randomness' of the different stimuli. It feels fairly simple, mainly using the GUI and just some python inline, to create something like:

    
    % Block Loop
    show_ot = random.randint(1,6)
    show_ct = random.randint(1,2)
    
    % nested Block Loop for the Ongoing Task
    % repeat this [show_ot] times
    % " " yes/no
    set cycles "[show_ot]" 
    
    % second nested Block Loop for the Critical Tasks
    if [show_ct] = 1 show Distractor Task
    if [ show_ct] = 2 show Ambiguous task
    
    Rinse and repeat highest loop oft as needed.
    

    Would you agree?

    What feels like an extra problem though: with this randomness I might end up presenting subjects with a trial consisting of only one of two critical trials. Is that something I'd just have to live with (i.e. discard these in my results)?

  • edited May 2014

    Glad that helped! I'm not quite sure what your pseudocode should do, but if you are trying to implement the 80% OT, 10% DT and 10% AT design, I wouldn't go for a completely random approach. That is: it might be better to randomize the order, but to make sure that the trial occurrence percentages are in fact 80-10-10.

    One way to do this, would be to create a loop with 10 cycles. In this loop, define a variable called trialtype, and use that variable as a Run if statement in your trial sequence. Would look something like the attached images:

    loop: use either the amount of repeats, or the Break if statement to stop the experiment at some point.

    sequence: use the Run if statements to selectively run a single trial sequence from one of the trial types.

    overview: design each of the single trial sequences any way you would want to.

  • edited May 2014

    EDIT

    I just realized, when using your setup (as above) I could just use a different keyboard response for each trial, without them intervening with one another. So let me rephrase my question: how would the OpenSesame command 'set correct_response "a;b"' look in Python inline?

    /EDIT

    Thanks alot. I will use this!

    Another quick question:
    in one trial, responses made aren't relevant. In other words: I want to count any button press (within allowed responses) to count as correct. I can't find a way to do this..

    I've been working with:

    
    if critical_task == 1:
        if use_this_number % 2 == 0:
            correct_response = "p"
        else:
            correct_response = "o"
    elif critical_task == 2:
        if use_this_number2 > 5:
            correct_response = "w"
    else:
    # critical task is 3, which means any button press (q,w,o,p) should count as correct
    

    This piece of code runs in the prepare bit of an inline_script at the start of my critical_trial_loop.

  • edited 6:52AM

    Hi Daan,

    As you note, you could simply use a different keyboard_response for every trial type. If you want to handle responses yourself, I would suggest using a single inline_script, placed directly after the keyboard_response:

    # preset correct to 0
    correct = 0
    
    # determine response correctness
    if critical_task == 1:
        if use_this_number % 2 == 0 and self.get("response") == "p":
            correct = 1
        elif self.get("response") == "o":
            correct = 1
    elif critical_task == 2:
        if use_this_number2 > 5 and self.get("response") == "w":
            correct = 1
    elif critical_task == 3:
        correct = 1
    
    # set correct as OpenSesame variable
    exp.set("correct", correct)
    

    Does that make sense?

  • edited 6:52AM

    It sure does! Looks like some things I tried, but never got the result I wanted. Guess I'm going with your approach now anyway, so doesn't really matter.

    Thanks so much for your advice so far. I might need you again in the near future, will let you know ;)

  • edited 6:52AM

    Hi Edwin,

    I've progressed somewhat in designing my experiment. It works so far, save the Ambiguous Task-trial: same problem as before basically, I can't seem to get the multiple correct responses to work.

    My trial for-loop:

    The AT_keyboard_response looks like this:

    Now, when I run a test-trial, [acc] is calculated correctly, except when an AT turns up. Somehow it won't accept any of four keypresses as correct. I've tried to implement some version of what you presented above, like so:

    
    
    # Set correct
    exp.set("correct", 1)
    
    print self.get("correct")
    # Prints 1 as expected
    print self.get("acc")
    # Prints 0, sadly enough
    

    And that's where I'm stuck basically. Any ideas?

  • edited 6:52AM

    Found a solution somewhere on the forum, don't ask how I missed that earlier!

    Thanks for helping out, you can close this one :)

  • edited June 2014

    Awesome! I'm glad you figured it out :) Will mark this one as solved!

    By the way: rather than the multiple options as the correct response in a keyboard_response item, you could have used the inline_script approach I describe in one of my previous posts in this thread.

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