Millisecond Forums

When is block.ontrialbegin executed?

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

By Blackadder - 9/25/2013

Hi All,


one question: when is


<block BLOCKname>
/ ontrialbegin = [...]
</block>


executed?  I'm asking specifically with regard to the following scenario.


Suppose you have


<trial TRIALname>
/ ontrialbegin = [counter = counter + 1]
/ branch = [if (something) trial.TRIALname]
</trial>


<block BLOCKname>
/ ontrialbegin = [counter = counter + 1]
/ trials = [1-10 = TRIALname]
</block>


Will block.ontrialbegin be executed only for the 10 times the block will call the trial OR will it also be executed when the trial branches into itself?


In any case, do I assume correctly that block.ontrialbegin always fires before trial.ontrialbegin?


Bye, Malte


By Dave - 9/25/2013

will it also be executed when the trial branches into itself?


This. block.ontrialbegin is defining global statements to be executed in *all trials* in the block. I.e.


<values>
/ count = 0
</values>

<block myblock>
/ ontrialbegin = [values.count+=1]
/ trials = [1=a]
</block>

<trial a>
/ stimulusframes = [1=mytext]
/ trialduration = 1000
/ branch = [trial.b]
</trial>

<trial b>
/ stimulusframes = [1=mytext]
/ trialduration = 1000
/ branch = [trial.a]
</trial>

<text mytext>
/ items = ("<%values.count%>")
</text>


is equivalent to


<values>
/ count = 0
</values>

<block myblock>
/ trials = [1=a]
</block>

<trial a>
/ ontrialbegin = [values.count+=1]
/ stimulusframes = [1=mytext]
/ trialduration = 1000
/ branch = [trial.b]
</trial>

<trial b>
/ ontrialbegin = [values.count+=1]
/ stimulusframes = [1=mytext]
/ trialduration = 1000
/ branch = [trial.a]
</trial>

<text mytext>
/ items = ("<%values.count%>")
</text>



Will block.ontrialbegin be executed only for the 10 times the block will call the trial OR will it also be executed when the trial branches into itself?


In any case, do I assume correctly that block.ontrialbegin always fires before trial.ontrialbegin?



No, actually it fires after, which you can see by doing something like this:


<values>
/ count = 0
</values>

<block myblock>
/ ontrialbegin = [values.count+=1]
/ trials = [1=a]
</block>

<trial a>
/ ontrialbegin = [values.count=666]
/ stimulusframes = [1=mytext]
/ trialduration = 1000
/ branch = [trial.a]
</trial>

<text mytext>
/ items = ("<%values.count%>")
</text>


Hope this helps,


~Dave

By Blackadder - 9/25/2013

Hi Dave, gold-standard answer! Thanks a lot.


Allow me a follow-up question. Is there an "on..." statement or something similar that fires ONLY when the block branches into the trial?


I know I could achieve about the same thing with some logic but I'd rather not since timing might screw things up.


By Dave - 9/25/2013

Allow me a follow-up question. Is there an "on..." statement or something similar that fires ONLY when the block branches into the trial?


No, but you can incorporate it directly into the /branch itself:


<values>
/ countmybranches = 0
</values>

<block myblock>
/ trials = [1=a]
</block>

<trial a>
/ stimulusframes = [1=mytext]
/ trialduration = 1000
/ branch = [if (true) {values.countmybranches+=1; trial.a}]
</trial>

<text mytext>
/ items = ("<%values.countmybranches%>")
</text>

By Blackadder - 9/25/2013

That's great. You can put logic into the branch statement as long as it contains a "trial" result somewhere. The possibilities have become even more endless!


Thanks again,
  Malte