Mixing local and global variables

PennController for IBEX Forums Support Mixing local and global variables

Tagged: 

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #11181
    lbrehm
    Participant

    I’m stuck on how to set and update variables! I’d like to keep a running total of ‘acceptability’ and then report it back to the user at the end. Here’s my try but something’s catastrophically (and perhaps obviously?) wrong. The variables seem to be of the wrong types, and they also don’t update.

    Minimum code below– fuller code here: https://farm.pcibex.net/r/eeUvts/


    newVar(‘trCount’,0).global()
    newVar(‘runAcc’,0).global()

    Sequence(“init”,”consent”,”demographics”, “instr”, “example”, pick(exptrials, batch), “break”, pick(exptrials, batch), SendResults(), “results”)

    Template(“diadia_items_2.csv”, row=>
    newTrial(“experiment”,
    newVar(‘trAcc’,0), // this one is local
    newImage( row.picture).size(“auto”, “50vh”).center().print(),
    newTextInput(“yours”, “”).log().size(300,30)
    .settings.before(newText(“What do YOU usually call this?”)).center().print(),
    newText(“Do other people in your community agree with you?”).center().print(),
    newScale(“agree”,100).slider().default(50).settings.css(“font-size”, “24px”).size(“40vw”).css(“max-width”, “unset”).log(),
    newCanvas(“container”, “40vw”, “2em”) // Container for layout
    .add( “left at 0%” , 0, newText(“No”).settings.css(“font-size”, “24px”))
    .add( “right at 100%”, 0, newText(“Yes”).settings.css(“font-size”, “24px”))
    .add( “center at 50%”, 30, getScale(“agree”)).print(), // Add slider to canvas

    // update vars
    getVar(‘trAcc’).set(getScale(‘agree’)).log(), // this should be local– just the answer to the scale
    getVar(‘runAcc’).set(v => v + getVar(‘trAcc’)).log(), // this one is global– the running accuracy total
    getVar(‘trCount’).set(v => v + 1).log(), // global– total trial counts

    newButton(“Next”)
    .print()
    .wait(),

    ));

    // Final screen
    newTrial(“results”,
    defaultText.print().center(),
    getVar(‘runAcc’).set(v => v / getVar(‘trCount’)),
    newText(“Thank you for your participation!”),
    newText(“You think you agree with your community “+runAcc+”% of the time.”), // not sure how to put this in to be evaluated
    newText(“Please return to Prolific and enter the following code: “+uniqueID),
    newButton().wait()
    )
    .setOption(“countsForProgressBar”,false ).noHeader();

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.