Howdy, Stranger!

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

Supported by

[open] Updating variables

edited December 2012 in OpenSesame

I feel I fail to do something very basic, namely, to create a variable and update its value during the experiment. I think I have figured out how to update the variable, but I am struggling to create the variable. Can anyone help?

I would like to do something along the following lines: (1) have the participant press a number key, (2) add the amount associated to the chosen key to a variable called 'CurrentValue', (3) display the value of this variable in a SketchPad, (4) save this value in the csv file.

The screenshot shows what I have built so far.

Image and video hosting by TinyPic

I have a sketchpad asking for a number, I had a keyboard item, I have inline code to update the variable, and I have another sketchpad to show the updated variable.

The error message I get is "Description: Variable 'CurrentValue' is not set in item 'feedbackTotal'. You are trying to use a variable that does not exist."

Comments

  • edited December 2012

    If you want a variable to be global (accessible anywhere in the experiment) you need to define the variable in the loop immediately after the experiment sequence above.

    I'm in class at the moment but can give you more detail later on this as I've recently done something similar.

    Boo.

  • edited December 2012

    As Boo says (edit: that's not really what he wrote, I see now, but it's still true), you can declare a variable global in order to access it from within other inline_scripts. However, if you want to use a variable as part of a sketchpad, or more generally whenever you want to use it with the [square brackets] notation, you have to use exp.set(). exp.set() will store the variable in a special way, so that it is recognized by OpenSesame as an experimental variable.

    Your error is simply that your variable does not have starting value. It's analogous to what happens when you type the following in a Python terminal (provided you have not used the name a before).

    a = a + 1

    Python will say

    NameError: name 'a' is not defined

    because you are using a to give a value, which is not logically possible. Does that make sense? You are doing the same thing, but using exp.set() and self.get():

    exp.set('CurrentValue', self.get('CurrentValue')+1)

    The solution is simply to give CurrentValue a starting value (such as 0) at the beginning of your experiment:

    exp.set('CurrentValue', 0)

    Cheers!

  • edited 1:22AM

    Actually, that rose was supposed to go to your response in another thread, but, I guess you can't take back a gift given :p

  • edited 1:22AM

    New problem: When I type in
    exp.set("CurrentValue",0)
    into the loop or experiment code and try to save it, it disappears.

  • edited 1:22AM

    Hi Frouke,

    The exp.set() statement is Python syntax, which you can use only in inline_script items. The OpenSesame script that you see when you click on the Edit script buttons uses a different, very simple syntax, which is described here.

    So I suspect that you are typing Python script where OpenSesame script is expected. If this doesn't help, could you perhaps provide some more details and explain what you are trying to do?

    Cheers!
    Sebastiaan

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