Millisecond Forums

noreplace on block begin not behaving as expected

https://forums.millisecond.com/Topic35317.aspx

By AndrewPapale - 4/19/2023

Hi Millisecond Team,

I tried to use noreplace and got some unexpected behavior I was wondering if you could shed some light on. Basically, it seems that the computation that is supposed to go with each scrfunc condition is not matching up correctly. I have checked the computations themselves and they are correct and where they are supposed to go. But the wrong ones are being called at the wrong times according to the logic of how I thought this was set up.  I was able to do a workaround with a text.scrfunc.nextvalue approach, but I'd like to understand why the noreplace approach doesn't work.  Thank you. - Andrew

<block experiment>
/ onblockbegin = [values.scrfunc = noreplace(“IEV”,”DEV”,”CEV”,”CEVR”)]
/trials = [1=list.triallist]
</block>

<list triallist>
/ items = (trial.experiment)
</list>

<trial experiment>
// display an animation, let the subject respond freely
/ validresponse = (“ “) // space bar = response
/ on trialend = [ return true;]
/ branch = [ return dispFeedback ] // now we want to display the outcome of the subject’s choice
</trial>

<trial dispFeedback>
/ ontrialbegin = [
    if (values.scrfunc == “IEV”){
        // compute IEV condition
    } else if (values.scrfunc ==“DEV”){
        // compute DEV condition
    } else if (values.scrfunc ==“CEV”){
        // compute CEV condition
    } else if (values.scrfunc == “CEVR”){
        // compute feedback for CEVR condition
    }
]
</trial>

<expt main>
/ blocks = [ 1 = experiment; ]
</expt>
By Dave - 4/19/2023

AndrewPapale - 4/19/2023
Hi Millisecond Team,

I tried to use noreplace and got some unexpected behavior I was wondering if you could shed some light on. Basically, it seems that the computation that is supposed to go with each scrfunc condition is not matching up correctly. I have checked the computations themselves and they are correct and where they are supposed to go. But the wrong ones are being called at the wrong times according to the logic of how I thought this was set up.  I was able to do a workaround with a text.scrfunc.nextvalue approach, but I'd like to understand why the noreplace approach doesn't work.  Thank you. - Andrew

<block experiment>
/ onblockbegin = [values.scrfunc = noreplace(“IEV”,”DEV”,”CEV”,”CEVR”)]
/trials = [1=list.triallist]
</block>

<list triallist>
/ items = (trial.experiment)
</list>

<trial experiment>
// display an animation, let the subject respond freely
/ validresponse = (“ “) // space bar = response
/ on trialend = [ return true;]
/ branch = [ return dispFeedback ] // now we want to display the outcome of the subject’s choice
</trial>

<trial dispFeedback>
/ ontrialbegin = [
    if (values.scrfunc == “IEV”){
        // compute IEV condition
    } else if (values.scrfunc ==“DEV”){
        // compute DEV condition
    } else if (values.scrfunc ==“CEV”){
        // compute CEV condition
    } else if (values.scrfunc == “CEVR”){
        // compute feedback for CEVR condition
    }
]
</trial>

<expt main>
/ blocks = [ 1 = experiment; ]
</expt>

It is honestly not clear to me -- not from your description, not from the code snippet (which is broken in all sorts of ways) -- what you believe to be not matching up correctly or on what that conclusion is based. Please elaborate.
By Dave - 4/19/2023

Dave - 4/19/2023
AndrewPapale - 4/19/2023
Hi Millisecond Team,

I tried to use noreplace and got some unexpected behavior I was wondering if you could shed some light on. Basically, it seems that the computation that is supposed to go with each scrfunc condition is not matching up correctly. I have checked the computations themselves and they are correct and where they are supposed to go. But the wrong ones are being called at the wrong times according to the logic of how I thought this was set up.  I was able to do a workaround with a text.scrfunc.nextvalue approach, but I'd like to understand why the noreplace approach doesn't work.  Thank you. - Andrew

<block experiment>
/ onblockbegin = [values.scrfunc = noreplace(“IEV”,”DEV”,”CEV”,”CEVR”)]
/trials = [1=list.triallist]
</block>

<list triallist>
/ items = (trial.experiment)
</list>

<trial experiment>
// display an animation, let the subject respond freely
/ validresponse = (“ “) // space bar = response
/ on trialend = [ return true;]
/ branch = [ return dispFeedback ] // now we want to display the outcome of the subject’s choice
</trial>

<trial dispFeedback>
/ ontrialbegin = [
    if (values.scrfunc == “IEV”){
        // compute IEV condition
    } else if (values.scrfunc ==“DEV”){
        // compute DEV condition
    } else if (values.scrfunc ==“CEV”){
        // compute CEV condition
    } else if (values.scrfunc == “CEVR”){
        // compute feedback for CEVR condition
    }
]
</trial>

<expt main>
/ blocks = [ 1 = experiment; ]
</expt>

It is honestly not clear to me -- not from your description, not from the code snippet (which is broken in all sorts of ways) -- what you believe to be not matching up correctly or on what that conclusion is based. Please elaborate.

I fixed the code up so the mistakes are gone and it's runnable. This is all working as expected, so I'm really not sure what you believe to be not working properly.

<values>
/ scrfunc = ""
/ condition = 0
</values>

<block experiment>
// onblockbegin = [values.scrfunc = noreplace(“IEV”,”DEV”,”CEV”,”CEVR”)] // wrong quotation marks
/ onblockbegin = [values.scrfunc = noreplace("IEV","DEV","CEV","CEVR")]
/trials = [1=list.triallist]
</block>

<list triallist>
/ items = (trial.experiment)
</list>

<trial experiment>
// display an animation, let the subject respond freely
// validresponse = (“ “) // space bar = response // wrong quotation marks
/ stimulusframes = [1=press]
/ validresponse = (" ")
// on trialend = [ return true;] //???
// branch = [ return dispFeedback ] // now we want to display the outcome of the subject’s choice
/ branch = [return trial.dispFeedback]
/ recorddata = false
</trial>

<text press>
/ items = ("Press SPACE")
</text>

<trial dispFeedback>
/ ontrialbegin = [
//if (values.scrfunc == “IEV”){ // wrong quotation marks
    if (values.scrfunc == "IEV"){
// compute IEV condition
        values.condition = 1;
//} else if (values.scrfunc ==“DEV”){ // wrong quotation marks
    } else if (values.scrfunc =="DEV"){
// compute DEV condition
        values.condition = 2;
//} else if (values.scrfunc ==“CEV”){ // wrong quotation marks
    } else if (values.scrfunc =="CEV"){
// compute CEV condition
        values.condition = 3;
//} else if (values.scrfunc == “CEVR”){ // wrong quotation marks
    } else if (values.scrfunc == "CEVR"){
// compute feedback for CEVR condition
        values.condition = 4;
};
    //script.debugbreak();
]
/ stimulusframes = [1=mytext]
/ validresponse = (0)
/ trialduration = 2000
</trial>

<text mytext>
/ items = ("This is condition #<%values.condition%> ('<%values.scrfunc%>').")
</text>

<expt main>
/ blocks = [ 1-4 = experiment; ]
</expt>

<data>
/ columns = (date time subject group session blocknum blockcode trialnum trialcode
    values.scrfunc values.condition)
</data>


By AndrewPapale - 4/20/2023

Dave - 4/19/2023
Dave - 4/19/2023
AndrewPapale - 4/19/2023
Hi Millisecond Team,

I tried to use noreplace and got some unexpected behavior I was wondering if you could shed some light on. Basically, it seems that the computation that is supposed to go with each scrfunc condition is not matching up correctly. I have checked the computations themselves and they are correct and where they are supposed to go. But the wrong ones are being called at the wrong times according to the logic of how I thought this was set up.  I was able to do a workaround with a text.scrfunc.nextvalue approach, but I'd like to understand why the noreplace approach doesn't work.  Thank you. - Andrew

<block experiment>
/ onblockbegin = [values.scrfunc = noreplace(“IEV”,”DEV”,”CEV”,”CEVR”)]
/trials = [1=list.triallist]
</block>

<list triallist>
/ items = (trial.experiment)
</list>

<trial experiment>
// display an animation, let the subject respond freely
/ validresponse = (“ “) // space bar = response
/ on trialend = [ return true;]
/ branch = [ return dispFeedback ] // now we want to display the outcome of the subject’s choice
</trial>

<trial dispFeedback>
/ ontrialbegin = [
    if (values.scrfunc == “IEV”){
        // compute IEV condition
    } else if (values.scrfunc ==“DEV”){
        // compute DEV condition
    } else if (values.scrfunc ==“CEV”){
        // compute CEV condition
    } else if (values.scrfunc == “CEVR”){
        // compute feedback for CEVR condition
    }
]
</trial>

<expt main>
/ blocks = [ 1 = experiment; ]
</expt>

It is honestly not clear to me -- not from your description, not from the code snippet (which is broken in all sorts of ways) -- what you believe to be not matching up correctly or on what that conclusion is based. Please elaborate.

I fixed the code up so the mistakes are gone and it's runnable. This is all working as expected, so I'm really not sure what you believe to be not working properly.

<values>
/ scrfunc = ""
/ condition = 0
</values>

<block experiment>
// onblockbegin = [values.scrfunc = noreplace(“IEV”,”DEV”,”CEV”,”CEVR”)] // wrong quotation marks
/ onblockbegin = [values.scrfunc = noreplace("IEV","DEV","CEV","CEVR")]
/trials = [1=list.triallist]
</block>

<list triallist>
/ items = (trial.experiment)
</list>

<trial experiment>
// display an animation, let the subject respond freely
// validresponse = (“ “) // space bar = response // wrong quotation marks
/ stimulusframes = [1=press]
/ validresponse = (" ")
// on trialend = [ return true;] //???
// branch = [ return dispFeedback ] // now we want to display the outcome of the subject’s choice
/ branch = [return trial.dispFeedback]
/ recorddata = false
</trial>

<text press>
/ items = ("Press SPACE")
</text>

<trial dispFeedback>
/ ontrialbegin = [
//if (values.scrfunc == “IEV”){ // wrong quotation marks
    if (values.scrfunc == "IEV"){
// compute IEV condition
        values.condition = 1;
//} else if (values.scrfunc ==“DEV”){ // wrong quotation marks
    } else if (values.scrfunc =="DEV"){
// compute DEV condition
        values.condition = 2;
//} else if (values.scrfunc ==“CEV”){ // wrong quotation marks
    } else if (values.scrfunc =="CEV"){
// compute CEV condition
        values.condition = 3;
//} else if (values.scrfunc == “CEVR”){ // wrong quotation marks
    } else if (values.scrfunc == "CEVR"){
// compute feedback for CEVR condition
        values.condition = 4;
};
    //script.debugbreak();
]
/ stimulusframes = [1=mytext]
/ validresponse = (0)
/ trialduration = 2000
</trial>

<text mytext>
/ items = ("This is condition #<%values.condition%> ('<%values.scrfunc%>').")
</text>

<expt main>
/ blocks = [ 1-4 = experiment; ]
</expt>

<data>
/ columns = (date time subject group session blocknum blockcode trialnum trialcode
    values.scrfunc values.condition)
</data>



Thanks Dave, I found a silly error on my part while troubleshooting today.  Sorry I didn't get back to you earlier, needed a break.  I'm glad this approach works as intended, it was above and beyond for you to fix up my example.  The "" discrepancies are probably because I typed up this code quickly in Mac OS text editor and then copied and pasted.  Cheers, Andrew
By Dave - 4/20/2023

AndrewPapale - 4/20/2023
Dave - 4/19/2023
Dave - 4/19/2023
AndrewPapale - 4/19/2023
Hi Millisecond Team,

I tried to use noreplace and got some unexpected behavior I was wondering if you could shed some light on. Basically, it seems that the computation that is supposed to go with each scrfunc condition is not matching up correctly. I have checked the computations themselves and they are correct and where they are supposed to go. But the wrong ones are being called at the wrong times according to the logic of how I thought this was set up.  I was able to do a workaround with a text.scrfunc.nextvalue approach, but I'd like to understand why the noreplace approach doesn't work.  Thank you. - Andrew

<block experiment>
/ onblockbegin = [values.scrfunc = noreplace(“IEV”,”DEV”,”CEV”,”CEVR”)]
/trials = [1=list.triallist]
</block>

<list triallist>
/ items = (trial.experiment)
</list>

<trial experiment>
// display an animation, let the subject respond freely
/ validresponse = (“ “) // space bar = response
/ on trialend = [ return true;]
/ branch = [ return dispFeedback ] // now we want to display the outcome of the subject’s choice
</trial>

<trial dispFeedback>
/ ontrialbegin = [
    if (values.scrfunc == “IEV”){
        // compute IEV condition
    } else if (values.scrfunc ==“DEV”){
        // compute DEV condition
    } else if (values.scrfunc ==“CEV”){
        // compute CEV condition
    } else if (values.scrfunc == “CEVR”){
        // compute feedback for CEVR condition
    }
]
</trial>

<expt main>
/ blocks = [ 1 = experiment; ]
</expt>

It is honestly not clear to me -- not from your description, not from the code snippet (which is broken in all sorts of ways) -- what you believe to be not matching up correctly or on what that conclusion is based. Please elaborate.

I fixed the code up so the mistakes are gone and it's runnable. This is all working as expected, so I'm really not sure what you believe to be not working properly.

<values>
/ scrfunc = ""
/ condition = 0
</values>

<block experiment>
// onblockbegin = [values.scrfunc = noreplace(“IEV”,”DEV”,”CEV”,”CEVR”)] // wrong quotation marks
/ onblockbegin = [values.scrfunc = noreplace("IEV","DEV","CEV","CEVR")]
/trials = [1=list.triallist]
</block>

<list triallist>
/ items = (trial.experiment)
</list>

<trial experiment>
// display an animation, let the subject respond freely
// validresponse = (“ “) // space bar = response // wrong quotation marks
/ stimulusframes = [1=press]
/ validresponse = (" ")
// on trialend = [ return true;] //???
// branch = [ return dispFeedback ] // now we want to display the outcome of the subject’s choice
/ branch = [return trial.dispFeedback]
/ recorddata = false
</trial>

<text press>
/ items = ("Press SPACE")
</text>

<trial dispFeedback>
/ ontrialbegin = [
//if (values.scrfunc == “IEV”){ // wrong quotation marks
    if (values.scrfunc == "IEV"){
// compute IEV condition
        values.condition = 1;
//} else if (values.scrfunc ==“DEV”){ // wrong quotation marks
    } else if (values.scrfunc =="DEV"){
// compute DEV condition
        values.condition = 2;
//} else if (values.scrfunc ==“CEV”){ // wrong quotation marks
    } else if (values.scrfunc =="CEV"){
// compute CEV condition
        values.condition = 3;
//} else if (values.scrfunc == “CEVR”){ // wrong quotation marks
    } else if (values.scrfunc == "CEVR"){
// compute feedback for CEVR condition
        values.condition = 4;
};
    //script.debugbreak();
]
/ stimulusframes = [1=mytext]
/ validresponse = (0)
/ trialduration = 2000
</trial>

<text mytext>
/ items = ("This is condition #<%values.condition%> ('<%values.scrfunc%>').")
</text>

<expt main>
/ blocks = [ 1-4 = experiment; ]
</expt>

<data>
/ columns = (date time subject group session blocknum blockcode trialnum trialcode
    values.scrfunc values.condition)
</data>



Thanks Dave, I found a silly error on my part while troubleshooting today.  Sorry I didn't get back to you earlier, needed a break.  I'm glad this approach works as intended, it was above and beyond for you to fix up my example.  The "" discrepancies are probably because I typed up this code quickly in Mac OS text editor and then copied and pasted.  Cheers, Andrew

Thanks for letting me know there was an actual mistake in the full code and that you were able to locate it!

If you encounter similar issues or questions in the future, sharing runnable code (and maybe some example data as well) that actually produces the issue in question when run will be more productive than a few isolated snippets (which may not even include the relevant mistake(s)) -- I probably could have saved you a few hours of debugging.

Short, self-contained examples are ideal, i.e. you need not necessarily share full scripts (which will contain many irrelevant things and will take much longer to understand and work through).