Howdy, Stranger!

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

Supported by

Extracting an item from list and displaying it as text in a sketchpad

edited March 2017 in OpenSesame

Dear Opensesame people,

I'm building a simple experiment in Opensesame and I'm stuck on a problem which has something to do with how the sketchpad script is structured by default.
My task is a version of the n-back in which items (caps lock letters) are presented one at a time. The number of letters in this study list must be random between 6 and 12, and I create the list at the beginning of the trial in an inline object. Then I call each single item of the list one at a time in a series of sketchpad in the sequence.

When I try to show the items calling them in the script where the text is suposed to be, the indication is shown in the slide as a text itself and it doesn't call the item from the list: as an example, I read [studylist[-itemnumber]] instead of C.
I tried to remove the inverted commas, but it looks like they are just a default thing in the text section of sketchpad function in Opensesame.

draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=18 html=yes show_if=always **text="[studylist[-12]]"** x=0 y=0 z_index=0

Any ideas?
Thank you in advance :)

Giorgio!

Comments

  • Hi Giorgio,

    The standard [variable_name] notation does not allow you to do anything except refer to a variable. If you want to do more, you can embed arbitrary Python code using [=python_code] notation.

    In your case, the following would seem to work:

    text=[=studylist\[-12\]]
    

    Note that the square brackets in the code need to be escaped (\[ and \]).

    See also:

    Cheers!
    Sebastiaan

  • Hi Sebastian :)
    Thank you very much, the problem was that the square brackets were not escaped!
    Sorry, maybe it is probably something I would have been aware of if I was more practical with python programming in general?
    G

  • I have a somewhat similar problem - I made a sketchpad and displayed 12 letters in it. The user should be able to click on however many letters he wants and should be able to see his selections on the screen. I stored the selections in an array, and then made the array into a string, and tried to display the variable on the sketchpad, but I get an error saying that the variable does not exist. Any ideas?

    Thanks!

    Mariana .

  • I think Opensesame generates the sketchpad script in the "preparation" phase before start running the actual sequence. If the array is actually generated DURING the sequence, then the sketchpad will not be able to find the array in the preparation phase. Have you tried to embed the array code in the preparation phase? You can do it with an inline object, writing the code in the "prep" sheet!

  • Hi Giorgio! Using a sketchpad item wasn't doing the trick for me ( even if I defined the variable in the preparation phase) , so I ended up using widgets and creating a form -- I defined a variable to the beginning of the experiment and managed to add the letters that the user clicked on, and then displayed it with a custom widget that returns user input.

  • Hi,

    Maybe using a feedback item also helps (for future experiments):
    http://osdoc.cogsci.nl/3.1/manual/stimuli/visual

    Best,
    Jarik

  • edited November 2021

    I have a related question. Is it possible to use the square-bracket notation (in a feedback item) to show the content of an element of an array created in JavaScript (for an online experiment)?

    For example after a javascript inline with this:

    vars.accblock1 = []
    for (let i = 1; i < 12 ; i++) {
      vars.accblock1[i] = 1;
    }
    

    How can I refer to vars.accblock1[1] in the feedback item script? The solution suggested with = seems not to work (a runtime error aborts the experiment), likely because = only works for variables created in python code?:

    text="[=accblock1\\[1\\]]"

  • Hi @HenkvanSteenbergen ,

    It's not terribly elegant, but you could include the index (i ) in te variable name, like so:

    vars.accblock1 = []
    for (let i = 1; i < 12 ; i++) {
      vars['accblock1_' + i] = 1
    }
    

    And then you can refer to the variable as [accblock1_1] in a feedback item.

    — Sebastiaan

  • That works! Thanks 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