Howdy, Stranger!

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

Supported by

[open] save responses into block variable table

edited September 2012 in OpenSesame

Hi,

another question:

I'd like to save responses to comparison of pairwise items independently of the keys I assigned into the "allowed_responses" variable.

Therefore I need to access this variable from an inline-script, to later define for example


if response == "f":
standardized_response = 0 if response == "j":
standardized_response = 1

Is there any way to do that?

Related to that to that question is the last entry of this

Comments

  • edited 6:29PM

    Certainly. You can use the self.get() and exp.set() as described here

    So basically, you would insert an inline_script after your response item that looks somewhat like this:

    if self.get('response') == "f":
       exp.set('standardized_response', 0)
    elif self.get('response') == "j":
       exp.set('standardized_response',  1)

    Cheers!

  • Hi, Sebastian,

    okay, this way would work, but do I have the possibilty to access the allowed_keys variable, to make my code work even if I change input keys?

    Best

  • edited 6:29PM

    There is a variable for the allowed keys, which you can access within an inline_script. It's called allowed_responses.

    You could use an inline_script like the following:

    # load allowed responses
    allowed = self.get("allowed_responses")
    
    # split allowed responses (these are separated by a semicolon)
    allowed = allowed.split(";")
    
    # recalculate to standardized response
    for option in range(0, len(allowed)):
        if self.get("response") == allowed[option]:
            self.experiment.set("standardized_response", option)
    

    In this script, first the allowed responses ("k;l") are accessed and separated and stored into a list variable (["k","l"]) called allowed.

    After this, for every option in this list ("k" and "l"), it is checked if this is equal to the response (could be "k").

    If this is the case ("k" == "k"), then the variable standardized_response is given the value corresponding to the place of this key in the keylist (for "k", this is 0, since Python starts counting at 0; for "l", this would be 1).

    Does this help at all? If not, please leave another comment!

  • About local and global variables

    I just want to add something about accessing variables that are defined in the interface.

    With the exception of variables defined in a loop item, all variables that are set via the interface are local, meaning that they are available within, but never outside, a given item. Examples are the "duration" box in a sketchpad and the "allowed_responses" box in a keyboard_response. This is convenient because it allows you to present, for example, a sequence of sketchpads without their durations getting mixed up.

    Because those variables are not made global, simply using

    my_var = self.get("allowed_responses")

    in an inline_script will not work if you set 'allowed_responses' via the interface. You will get the following error message:

    Variable 'allowed_responses' is not set in item 'inline_script'

    As you may have guessed, the solution is to make the variable global yourself. You can achieve this by either:

    • defining the variable, called, for example 'allowed', in a loop item, or
    • defining 'allowed' in an inline script at the very beginning of your experiment, like so:

    exp.set("allowed", "z;/")

    This allows you to:

    • set the allowed responses in a keyboard_response to [allowed] instead of z;/
    • access the variable in an inline script as described above

    (Note that you should not name your own global variable 'allowed_responses' because typing [allowed_responses] in the allowed responses box will give a recursion error.)

    Retrieving local variables anyway

    All the above being said, for plastic_students' specific situation it's probably best to retrieve the local variable in an inline_script anyway, because he wants the code provided by Sebastiaan to work even if he changes the allowed responses in the keyboard_response item.

    So how would we do this? By specifically indicating from which item a variable has to be retrieved. Getting, for example, the variable 'allowed_responses' from a keyboard_response item called 'my_keyboard_response' in an inline_script item works like so:

    allowed = exp.items["my_keyboard_response"].get("allowed_responses")

    And from here on, Edwin's code should work fine!

    Note why this works, even when you have multiple keyboard_response items in your experiment: You use the item's name (which is unique) as a key to retrieve the desired item information.

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

  • edited September 2012

    Woops, my bad! I thought it was a global one. Should've checked first.

    Thanks for the addition!

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