Howdy, Stranger!

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

Supported by

[solved] Here's an example of code that only works in the prepare phase (Why is this?)

edited October 2013 in OpenSesame

Greetings.

The script below doesn't work. However, if I move

 exp.set('TimeAtSessionStart',self.time())

from the run phase to the prepare phase, or even if a copy it so that it's in both the prepare and run phase, then it works. Can anyone provide clarification on why this is, and what the more general implications might be? Thanks.

Richard

# Generated by OpenSesame 0.27.4 (Frisky Freud)
# Mon Oct 14 13:56:19 2013 (nt)
# <http://www.cogsci.nl/opensesame>

set foreground "white"
set subject_parity "even"
set description "Default description"
set title "New experiment"
set sampler_backend "legacy"
set coordinates "relative"
set height "768"
set mouse_backend "xpyriment"
set width "1024"
set compensation "0"
set keyboard_backend "legacy"
set background "black"
set subject_nr "0"
set canvas_backend "xpyriment"
set start "experiment"
set synth_backend "legacy"

define inline_script inline_script
    set _run "exp.set('TimeAtSessionStart',self.time())"
    set _prepare ""
    set description "Executes Python code"

define sequence experiment
    run inline_script "always"
    run welcome "always"

define sketchpad welcome
    set duration "keypress"
    set start_response_interval "no"
    set description "Displays stimuli"
    draw textline 0 0 "Time:  [TimeAtSessionStart]" center=1 color=white font_family="serif" font_size=32 font_italic=no font_bold=no show_if="always" html="yes"

R

Comments

  • edited 8:06PM

    Hi Richard,

    This is because a sketchpad's canvas is constructed during the prepare phase, which occurs before the run phase. Therefore, the contents of a sketchpad cannot depend on variables that are set during the run phase. In your case, the order of events is as follows:

    • Run sequence experiment
      • Prepare inline_script
      • Prepare welcome sketchpad (i.e. create the canvas)
      • Run inline_script
      • Run welcome sketchpad (i.e. show the canvas)

    Does that clear things up?

    The prepare-run strategy is described in more detail here:

    Cheers,
    Sebastiaan

    Buy Me A Coffee

  • edited October 2013

    Thanks Sebastiaan,

    This helps some, but I think I'm still missing a concept. The slightly expanded script, below, properly includes the exp.set function in the prepare rather than the run phase of "inline_script". However, for "inline_script_in_loop", the same exp.set command is used in the run rather than in the prepare phase, and yet the entire script works. (Moreover, the script seems to work the same way whether inline_script_in_loop includes the exp.set command in the prepare or the run phase). With respect to sketchpad usage, it appears exp.set does work in the run phase, but only if exp.set has also been used previously in the prepare phase. But I don't have a sufficient grasp of the prepare/run architecture to understand why this is.

    # Generated by OpenSesame 0.27.4 (Frisky Freud)
    # Wed Oct 16 03:15:19 2013 (nt)
    # <http://www.cogsci.nl/opensesame>
    
    set foreground "white"
    set subject_parity "even"
    set description "Default description"
    set title "New experiment"
    set compensation "0"
    set coordinates "relative"
    set height "768"
    set mouse_backend "xpyriment"
    set width "1024"
    set sampler_backend "legacy"
    set keyboard_backend "legacy"
    set background "black"
    set subject_nr "0"
    set canvas_backend "xpyriment"
    set start "experiment"
    set synth_backend "legacy"
    
    define sequence sequence
        run inline_script_in_loop "always"
        run message_in_loop "always"
    
    define sketchpad message_in_loop
        set duration "keypress"
        set description "Displays stimuli"
        draw textline 0 0 "Looped Time:  [TimeNow]" center=1 color=white font_family="mono" font_size=18 font_italic=no font_bold=no show_if="always" html="yes"
    
    define inline_script inline_script_in_loop
        set _run "exp.set('TimeNow',self.time())"
        set _prepare ""
        set description "Executes Python code"
    
    define sequence experiment
        run inline_script "always"
        run message "always"
        run loop "always"
    
    define inline_script inline_script
        set _run ""
        set _prepare "exp.set('TimeNow',self.time())"
        set description "Executes Python code"
    
    define sketchpad message
        set duration "keypress"
        set start_response_interval "no"
        set description "Displays stimuli"
        draw textline 0 0 "Time:  [TimeNow]" center=1 color=white font_family="serif" font_size=32 font_italic=no font_bold=no show_if="always" html="yes"
    
    define loop loop
        set repeat "1"
        set description "Repeatedly runs another item"
        set item "sequence"
        set column_order ""
        set cycles "5"
        set order "random"
        run sequence
    
    

    -- Richard

    R

  • edited 8:06PM

    Hi Richard,

    Once you have set a variable, it will remain set. (Unless you call exp.unset(), but that is rare.) But even though you therefore don't get a 'Variable [x] is not set' error, the behavior of your script is probably not what you want. More specifically, you will see that the timestamp shown in the message_in_loop sketchpad always lags behind by one cycle. This is because, again, the exp.set() statement is in the run phase of inline_script_in_loop and is therefore executed after message_in_loop has been prepared.

    Does that make sense? It can be a bit tricky, but if you have a hard time following the order of events, try to draw them out for yourself following the simple rule: Within a single sequence all items are first prepared and then run.

    Cheers,
    Sebastiaan

    Buy Me A Coffee

  • edited 8:06PM

    Yes. This makes sense now. Thank you.

    R

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