Reply To: log global vs. local variable

PennController for IBEX Forums Support log global vs. local variable Reply To: log global vs. local variable

#6316
mschrumpf
Participant

Hello everyone.
If you don’t mind me barging in, I have the same problem. Either the fix is not working for me, or I am doing something wrong. Either way, I would appreciate some feedback on this.
I want to record some demographic data at the start of the experiment:

newTrial( "Angaben" , 
    newText("Ueberschrift", "<h2>Stichproben-relevante Angaben</h2>").center().print()
    ,
    newTextInput("inputAlter")
    .size("100px")
    ,
    newScale("inputGeschlecht", "m&auml;nnlich", "weiblich", "divers")
    ,
    newScale("inputHaendigkeit", "linksh&auml;ndig", "rechtsh&auml;ndig")
    ,
    newTextInput("inputGeboren")
    ,
    newTextInput("inputWohnsitz")
    ,
    newScale("inputDeutsch", "ja", "nein")
    ,
    newTextInput("inputMuttersprache")
    ,
    newTextInput("inputProlific-ID")
    ,
    newCanvas("Canvas", 600, 320)
        .add( 0,    0,  newText("Alter:"))
        .add( 400,  0,  getTextInput("inputAlter").log())
        .add( 0,    40,  newText("Geschlecht:"))
        .add( 400,  40,  getScale("inputGeschlecht").log())
        .add( 0,    80,  newText("H&auml;ndigkeit"))
        .add( 400,  80,  getScale("inputHaendigkeit").log())
        .add( 0,    120,  newText("Geboren in (Bundesland/Staat):"))
        .add( 400,  120,  getTextInput("inputGeboren").log())
        .add( 0,    160,  newText("Derzeitiger Wohnsitz (Bundesland/Staat):"))
        .add( 400,  160,  getTextInput("inputWohnsitz").log())
        .add( 0,    200, newText("Deutsch als Muttersprache?"))
        .add( 400,  200, getScale("inputDeutsch").log())
        .add( 0,    240, newText("Muttersprachen (au&szlig;er Deutsch):"))
        .add( 400,  240, getTextInput("inputMuttersprache").log())
        .add( 0,    280, newText("Prolific-ID:"))
        .add( 400,  280, getTextInput("inputProlific-ID").log())
        .print()
    ,
    newText("Warnung1", "Bitte f&uuml;llen Sie die Pflichtangaben aus.")
        .color("red")
        .italic()
        .center()
        .hidden()
        .print()
    ,
    newButton("Weiter") 
        .center()
        .print()
        .wait(
            getTextInput("inputAlter").test.text(/.+/)
            .and(getTextInput("inputGeboren").test.text(/.+/))
            .and(getTextInput("inputWohnsitz").test.text(/.+/))
            .and(getTextInput("inputProlific-ID").test.text(/.+/))
            .and(getScale("inputGeschlecht").test.selected())
            .and(getScale("inputHaendigkeit").test.selected())
            .and(getScale("inputDeutsch").test.selected())
                .failure( 
                    getText("Warnung1")
                    .hidden()
                    ,
                    newTimer(100)
                    .start()
                    .wait()
                    ,
                    getText("Warnung1").visible() )
    ,
    newVar("Alter")
        .global()
        .set( getTextInput("inputAlter") )
    ,
    newVar("Geboren")
        .global()
        .set( getTextInput("inputGeboren") )
    ,
    newVar("Wohnsitz")
        .global()
        .set( getTextInput("inputWohnsitz") )
    ,
    newVar("Muttersprache")
        .global()
        .set( getTextInput("inputMuttersprache") )
    ,
    newVar("Prolific-ID")
        .global()
        .set( getTextInput("inputProlific-ID") )
        ,
    newVar("Geschlecht")
        .global()
        .set( getScale("inputGeschlecht") )
    ,
    newVar("Haendigkeit")
        .global()
        .set( getScale("inputHaendigkeit") )
    ,
    newVar("Deutsch")
        .global()
        .set( getScale("inputDeutsch") )
    
            )
    .log("Alter", getVar("Alter"))
    .log("Geschlecht", getVar("Geschlecht"))
    .log("Haendigkeit", getVar("Haendigkeit"))
    .log("Geboren", getVar("Geboren"))
    .log("Wohnsitz", getVar("Wohnsitz"))
    .log("Deutsch", getVar("Deutsch"))
    .log("Muttersprache", getVar("Muttersprache"))
    .log("Prolific-ID", getVar("Prolific-ID"))
)
.setOption("countsForProgressBar", false)
.setOption("hideProgressBar", true);

Then in a later trial, I want to call back to the variables entered here to write them into each line of the results file:

Template( "itemlist_1_1.csv" , //Aufbau parallel zu "exercise.csv"
    row => newTrial( "Experiment" ,
        newKey("Enter", "Enter")
            .callback(
                getButton("Weiter").click()
                )
        ,
        newText("")
        .settings.css({
        "padding-top": "100px"
        })
        .print()
        ,
        newText("prompt", row.prompt)
        .settings.cssContainer({
        "background-color": "lightgrey",
        "width": "800px",
        "border-radius": "5px",
        "margin": "auto",
        "align": "center",
        "text-align": "center",
        "padding": "5px",
        "font-size": "large"})
        .print()
        .log()
        ,
        newText("Line", "<hr>")
        .settings.css({
        "width": "100%",
        "margin": "auto",  
        })
        .print()
        ,
        newTextInput("Continuation", "")
        .lines(1)
        .center()
        .settings.css({
            "border": "solid 2px royalblue",
            "border-radius": "5px",
            "width": "75%",
            "align": "center",
            "text-align": "left",
            //"padding": "10px 5px 0px 5px",
            "font-size": "large",
            "margin": "auto"
        })
        .print()
        .log()
        ,
        newText("Line", "<hr>")
        .settings.css({
        "width": "100%",
        "margin": "auto",  
        })
        .print()
        ,
        newText("Warnung3", "Bitte geben Sie eine Fortsetzung ein.")
        .color("red")
        .italic()
        .center()
        .hidden()
        .print()
        ,
        newButton("Weiter")
        .center()
        .print()
        .wait( getTextInput("Continuation").testNot.text("")
            .failure( 
                getText("Warnung3")
                .hidden()
                ,
                newTimer(100)
                .start()
                .wait()
                ,
                getText("Warnung3").visible() ) 
        )
    )
    .log("Alter", getVar("Alter"))
    .log("Geschlecht", getVar("Geschlecht"))
    .log("Haendigkeit", getVar("Haendigkeit"))
    .log("Geboren", getVar("Geboren"))
    .log("Wohnsitz", getVar("Wohnsitz"))
    .log("Deutsch", getVar("Deutsch"))
    .log("Muttersprache", getVar("Muttersprache"))
    .log("Prolific-ID", getVar("Prolific-ID"))
    //Zeichnet demografische Angaben aus Folie 2 in jeder Ergebniszeile auf
    .log("id", row.id)
    .log("cond", row.cond)
    .log("np1", row.np1)
    .log("np2", row.np2)
    .log("coref", row.coref)
    .log("vclass", row.vclass)
    .log("verb", row.verb)
    .log("list", row.list)
    .log("prompt", row.prompt)
    //Zeichnet Werte aus den angegebenen Tabellenspalten fuer die aktuelle Tabellenzeile auf 
    .log("Continuation", getVar("Continuation"))
)

But just like in Peiyao’s case, the lines .log("Alter", getVar("Alter")) and so on only insert “undefined” into the results file each time. The logging works fine on the demographic information trial. But later in the actual experiment, all variables are “undefined”. What can I do to fix this?