Howdy, Stranger!

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

Supported by

[solved] Setting the number of cycles in a loop programatically

edited June 2014 in OpenSesame

So I am skipping the built in variables approach as I prefer to use my own arrays and variables for sequencing and presentation of trials.

I do this by defining a set of global variables at the beginning. There are several block sequences within which there are blockloops that contain trial sequences. Although the experiment has many different blocks, the basic structure is the same; thus I can reuse the same objects. The only thing I do is make sure that all the variables (stimulus and response arrays are setup before the block loop begins and within the block loop I have another inline script that sets the presentation stimuli and responses for each trial).

So far so good. I am puzzling how to set the number of trials (cycles) for the loop using a global variable.

In the script mode for the block loop, I see a line that says

set cycles "8"

How can I reset this to a global variable value (say something called gblocksize?) that has been set earlier by an inline script? I know that this script mode can't actually deal with python. What is the trick to getting to accept code? If I just naively say "[gblocksize]" instead of "8" that does not work as the GUI objects.

Thanks.

Comments

  • edited June 2014

    Ok I am using the approach suggested in an older forum post which is just about deleting the loop object and using an inline script to loop in the run tab. When I do this and set the global variable just before the prepare and run for trial sequence, it doesn't seem to recognize the variable inside the sketchpad. Wonder if this is related to scope.

    Here is what I am trying to do

    All variables starting with g have been defined as globals at start of experiment

    contents of RUN tab in the loop in-line script

    for i in range(gblocksize):
            gtrialnumber = i 
            gtrialstimulus = gitems[gitemsorder[gtrialnumber]]
            gtrialresponse = gitemsresponse[gitemsorder[gtrialnumber]]
            exp.items["trialsequence"].prepare()
            exp.items["trialsequence"].run()
    

    Problem is that the sketchpad inside the trialsequence does not recognize [gtrialstimulus] even though values are correctly set inside the loop (can check with print statement). Now earlier I had similar code running in a script inside the trialsequence and that worked. Why should this matter as the g variables are all previously defined as global.

    If I define the gtrialstimulus outside the loop to a fixed value, then the sketchpad seems to recognize it (say in a different inline script that is outside the trialsequence as well).

    So I guess my question is: How can I set the values within the loop so that it correctly changes the global variable gtrialstimulus and is recognized in the sketchpad (as it was doing previously when the code was inside the trialsequence itself.

  • edited 6:29PM

    I do find that the g variables being changed in an inline script inside the trialsequence object are recognized. One other oddity. Inside this loop, the count_trialsequence seems to start from 1, not 0. Is this documented behavior that we can rely on?

  • edited June 2014

    Now its started from zero but it loops the trial n+1 instead of n

    for i in range(8):
            exp.items["trialsequence"].prepare()
            exp.items["trialsequence"].run()
    

    This shows 9 trials, instead of 8. Puzzled. The count_trialsequence does start from zero.

  • edited June 2014

    I've put a print statement that counts the number of trials. It goes from 0 to 8 for some weird reason, instead of 0 to 7. Any ideas?

  • edited June 2014

    Above issue likely due to not turning off the trial sequence using "never". Problem with counter continues (it starts at 1 instead of 0).

  • edited 6:29PM

    https://www.dropbox.com/s/krjy4vs2desdm73/counttrialsequence.opensesame.tar.gz

    shows this counting from 1 instead of zero. Is this normal?

  • edited 6:29PM

    I think this file gets at what I was looking for.. A custom counter that does start from zero. One thing I learned was to use to exp.set and exp.get for simple numeric or string variables. For arrays/objects, the only option is perhaps using the global definition.

    https://www.dropbox.com/s/utk8itsbaootdv4/customcounter.opensesame.tar.gz

  • edited 6:29PM

    Wow, you've been busy! To make life easier for people reading (and possibly answer) your question, could you let us know whether you've been able to resolve this issue, and if not, where you are exactly?

  • edited June 2014

    Yes, this got resolved. See the lessons learnt post for a generic description.

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