Howdy, Stranger!

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

Supported by

[solved] Using variables to set loop repeat

edited August 2011 in OpenSesame
Hi:

I'd like to use a variable set in a script to set the number of loop repeats.  I have a script that does this:

self.experiment.set('num_lists', 6)

and then I try and set the loop repeat value to [num_lists] and it gives me the following error:


p, li { white-space: pre-wrap; }

'%s' is not a valid value for repeat. Expecting a positive numeric value.


Any ideas so that I don't have to hard code this stuff?


Thanks,

Per


Comments

  • edited August 2011

    Hi Per,

    Thank you for christening the brand new shiny forum!

    Yes, you can certainly do this, but in a non-documented hacky way, by accessing the OpenSesame internals. For example, to set the repeat value of a loop item called my_loop to 4, you do the following in an inline script before the loop item.

    self.experiment.items["my_loop"].repeat = 4

    You can access the internals of all the items like this, through the experiments.items dictionary.
    And I'll look into the error that you report, because that looks like a bug!

    Sebastiaan

  • edited 12:42PM

    Hi Sebastiaan:


    Works like a charm! 

    Thanks!
    Per

  • edited 12:42PM

    Me again!


    When are loop counts updated?  Now that the I can set the number of repeats for a loop (the cycles also seems to work), I'd like to use the current loop count to present different stimuli.  The problem is that my loop count available to me in the __prepare__ of an inline script at the start of the sequence inside the loop does not seem to iterate beyond 0.

    For example, I'm trying something like this:

    p, li { white-space: pre-wrap; }

    item_index = self.get('count_TrialLoop')


    and then pick a word from a list based on that item_index, but it doesn't seem to change...


    Any thoughts?

    Thanks,
    Per

  • edited 12:42PM

    Hi Per,

    The loop counts are updated every time that a loop is executed. So the counter is increased at the start of the run phase. The same applies to all items.

    But I can understand your confusion. The thing is that you need the counter of the item that is called by the loop item (probably a sequence), rather than the counter of the loop item itself: The loop is executed only once, the sequence in it is executed multiple times.

    So something like this should work:
    item_index = self.get("count_my_sequence")

    Good luck!

    Sebastiaan

  • edited 12:42PM

    Great! That did it! That also cleared up the loop confusion.

    Best,
    Per

  • Hi @sebastiaan,

    I just wanted to confirm that the method mentioned here:
    self.experiment.items["my_loop"].repeat = 4
    is still working, since I have a similar problem. My experiment has 4 blocks with the same trial sequence, but the number of trials in each block is different. I was thinking to use this way to set up the number of repeats for each block. It seems that the method is not working in my case. I have tried to put the code into both the prepare and run phase.

    Thanks!
    Han

  • Hi Han,

    In recent versions of OpenSesame, variables are properties of the var object. So you can still programmatically change the repeat variable of a loop item, but it would work like this:

    items['my_loop'].var.repeat = 4
    

    An alternative would be to edit the script of the loop item, and define the variable repeat in terms of another variable (my_repeat, say) which you could then define in a loop at a higher level of the structure.

    set repeat [my_repeat]
    

    Cheers!
    Sebastiaan

  • Hi @sebastiaan,

    I'm not sure if this is the right place for my question, but this topic was the most related one that I found.

    I have a loop and a sequence inside with several sketchpads.

    I want to skip some of the sketchpads in the first trial of the loop.

    Do we have a variable as the "loop counter" so I can use it in the sequence "Run if" column?

    I want to say "Run if the loop counter is not one!" (so I can skip this sketchpad in the first trial and then have it in the rest).


    Thanks in advance,

    Kian

  • Hi, there are the count variables.

    they are labeled as "count_item_name", so if you have a sketchpad called, "stim_presentation", the variable would be called "count_stim_presentation". You can use that in the run if statement (run only if it is bigger than 0)


    Hope this helps,

    Eudard

    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