Howdy, Stranger!

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

Supported by

[solved] Saving text input variables in a loop for later use outside the loop

edited May 2013 in OpenSesame

Dear Sebastian.

I'm using Opensesame for an experiment in which I let participants play several economic games. (followed by a spatial cueing task).
Participants have to divide money, which occurs through a tekst form (saying: how much money do you want to keep for yourself). There are 4 rounds of games, and each round consists out of 4 different games, 2 of which use a tekst form. So it's a loop within a loop.

In the end, I want to add up all the money they decided to keep. In other words, I want to use the tekst_input variable set in the loop outside the loop. However, when I'm using a feedback form, the tekst_input variable seems to have vanished (or been reset).

So how can I use the tekst_input form's variables outside their specific loops? simply adding an inline script saying exp.get("relevant_variable") doesn't work.

Best
Wouter Wolf
Free University Amsterdam

Comments

  • edited May 2013

    I also realized that variables saved in a loop are a locally stored variables, so I tried to use:
    exp.items["SubmissiveDictator2Round1"].get("form_var").

    with SubmissiveDictator2Round1being the input_text form in which the relevant variable is created. But it didn't work.

    The loop is only there to randomize certain aspects of the game, but every round has its own tekst_input form (conditional of round number). So if it would just save the response variable globally once the problem would be solved, since the variable wouldn't be overwritten by a following trial.

  • edited 7:41PM

    Hi Wouter,

    Welcome to the forum!

    Several things come to mind when you say you can't use your form_text_input variables to provide participants with feedback.

    Firstly, did you rename the response variables in the form_text_input items? The response variable is called 'response' by default, but it's good practice to rename this into something more meaningful. And especially so when you use multiple form_text_input items in one sequence. Otherwise, every proceeding text input will overwrite the previous value. If you give your variables distinctive names, you won't have this problem.

    The name of the response variable can be changed here:

    image

    However, when I'm using a feedback form, the tekst_input variable seems to have vanished (or been reset).

    Just to clarify, do you mean a feedback item? The green icon with the hashtag? In that case, you should be able to display previously-defined (response) variables by using the square-bracket method, like so:

    image

    (given that you named the form_text_input variables 'response1', and 'response2', of course). Did you use this method? And did you place the feedback item somewhere after the text input is collected?

    For more information on providing feedback, please see:

    So how can I use the tekst_input form's variables outside their specific loops? simply adding an inline script saying exp.get("relevant_variable") doesn't work.

    Did you place your code in the Prepare phase tab of your inline_script item? And again, did you place the inline_script item somewhere after the text input is collected? Something like the following should work:

    # Use the experiment function self.get() to obain in-the-GUI-defined variables:
    amount1 = self.get("response1")
    amount2 = self.get("response2")
    
    # Calculate the total:
    total_amount = amount1 + amount2
    
    # Use the experiment function exp.set() to make an in-an-inline-script defined variable
    # availabe in the GUI as well:
    exp.set("total", total_amount)
    

    For more information about setting and getting variables, please see:

    I uploaded a working example experiment here (download, change the extension into '.opensesame' (instead of '.txt' and open as normally):

    Does this help?

    Best,

    Lotje

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

  • edited May 2013

    Hey Lotje,

    Thanks for the feedback, but my problems are a little more complex than that. :-)
    Working with feedback items is working just fine within the loop (I have several of them programmed there). The only problem is that when I use a feedback item after the loop, using a variable defined within the loop, it won't work.

    Maybe the best way to understand my problem is this:

    If you have an empty open sesame file, put a loop in the main (experiment) sequence, and add a variable to the loop called "Round". Set the loop to 2 cycles: in the first cycle variable "Round" = 1, in the second cycle variable "Round" = 2.
    This loop should already contain a sequence (to be clear, call that sequence "loopseq"). Place two sequences in loopseq, and make the two sequences ("sequence1" and "sequence2") conditional on the variable "Round": so for sequence1 "Round"=1, and for sequence2 "Round"=2.
    Now put a tekst_input file in both sequences. Call the response variable of the tekst form in sequence1 "var1" and the response variable of the tekst form in sequence2 "var2".

    As long as the feedback items are within the loop there is no problem. However, if you put a new sequence after the loop (so in the primary experiment sequence), and put a feedback item containing [var1] and [var2] in that sequence, opensesame gives an error, saying that it is unable to find variable [var1].

    I think the problem is that opensesame somehow resets the variable once the loop starts over: as long as I remain within a loop cycle I can use the variable [var1], however, when the loop starts over (this time running sequence2) [var1] is no longer available.

    Do you know what I should do to make [var1] available outside its own loop cycle?

    Best
    Wouter

  • edited May 2013

    Hi Wouter,

    Working with feedback items is working just fine within the loop (I have several of them programmed there). The only problem is that when I use a feedback item after the loop, using a variable defined within the loop, it won't work.

    In the example experiment I uploaded I'm doing exactly that: I use in-the-previous-sequence-defined variables in both an inline_script item and a feedback item:

    image

    Note that this strategy only works with feedback items and Prepare phase tabs of inline_script items because, in contrast to for example form items and sketchpad items, they are constructed at the moment that they are shown.

    For more information about the prepare-run strategy OpenSesame uses, please read this article:

    I think the problem is that opensesame somehow resets the variable once the loop starts over: as long as I remain within a loop cycle I can use the variable [var1], however, when the loop starts over (this time running sequence2) [var1] is no longer available.

    OpenSesame does not reset or delete any variables, and in-a-given-loop defined variables are not local in the sense that they are not available outside that loop. As soon as a variable (e.g. 'text_input1' is created somewhere during the experiment, its value (e.g. the text input '10') remains available until it's overwritten by the text input (e.g. '5') on the next occurrence.

    However, because of your specific sequences-within-a-sequence structure

    image

    it seems that the following is going on:

    • Even though you use Run-if statements to run only one of the two sequences, both are prepared anyway (see the article mentioned above for more information).
    • During this preparation phase, the text_input_form contains no text yet (because the default text to start with is an empty string, ''), and for one of the two forms it remains that way (because the item is not run).
    • The text_input_form item uses the text it contains as the response variable (in your case 'var1' or 'var2'). In one of the items, the response variable will therefore contain the input text given by the participant (e.g. '10'). The value of the other variable will remain ''.
    • As a consequence, your feedback item will show one empty string and one 'real' string.
    • You mention that "opensesame gives an error, saying that it is unable to find variable [var1]". Because of the prepare-run strategy mentioned before, this cannot happen with a feedback item if it is placed somewhere below your form_text_ input items.

    As a solution to the empty-string problem, I would simply advise you to place the form_text_input items in a loop item rather than in a sequence item. A loop item is not prepared in advance, which is particularly convenient in situations such as yours (again, see the above-mentioned article). So I think changing your experimental structure into this:

    image

    will solve your problem.

    For a new example experiment, see:

    Does this make sense? Don't hesitate to post further questions if something remains unclear.

    Best,

    Lotje

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

  • edited 7:41PM

    Hey Lotje,

    Thanks, that seems to be what is going on.
    The only problem now is that the games (which would be l1 and l2 in your screen) consist out of multiple screens including sketchpads, tekst forms, and feedback items. This is necessary because it is kind of an interactive design.

    Correct me if I'm wrong, but a loop without a sequence in it can only consist out 1 item right? So can I still use this trick by keeping my sequences of items intact, but replace the tekst input items by loops, containing these tekst input items.

    So for example: suppose I'd have loopsequence with s1 and s2 (just like your first screenshot) and s1 and s2 have for example a sketchpad (sp1/sp2), a tekst input (ti1/ti2)and a feedback item (fb1/fb2). Can I simply replace ti1/ti2 by l1 containing ti1 and l2 containing ti2?

    Thanks in advance!

    Wouter

  • edited May 2013

    Hi Wouter,

    a loop without a sequence in it can only consist out 1 item right?

    Yes, you're absolutely right! So perhaps what you can do is wrap the two loop items around two (or whatever number of different games you have) new sequence items rather than a single form_text_input item (as in the previous example). As long as one of the loop items is not run (depending on the Run-if condition), the potential empty-string problem caused by the sequence within this loop will not occur either.

    Does that make sense?

    So, the new structure will look something like this:

    image

    The new experiment is uploaded here:

    Best wishes,

    Lotje

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

  • edited 7:41PM

    Yes, now it works.

    Thanks a lot for your feedback!

    Best
    Wouter

  • edited 7:41PM

    Great! :)

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

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