Millisecond Forums

total count for "values"

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

By sdandeneau - 11/12/2015

Hi, 

I've created a 'value'  (e.g. "response" is : 0 or 1 for each trial) depending on what the subject responds. I would now like to create a second value that computes the sum of the "response" value across all trials at the end of the experiment, i.e. what is the total of "response", in order to easily compute a "final response score". 

It would be very similar to "trial.sometrial.totaltrialcount/totalcorrect etc..." but I can't seem to figure out this option for a value that I created.

Thanks in advance. 
Stéphane 
By Dave - 11/12/2015

You need to create another <values> entry and sum up the response across all trials.

<values>
/ response = 0
/ sumresponses = 0
</values>

<block myblock>
/ trials = [1-10=mytrial]
</block>


<trial mytrial>
/ stimulusframes = [1=mytext]
/ validresponse = (32, 37)
/ ontrialend = [if (trial.mytrial.response == 32) values.response=1 else values.response=0;
    values.sumresponses+=values.response; ]
</trial>

<text mytext>
/ items = ("Press D or K. D -> values.response = 1; K -> values.response = 0")
</text>

<data>
/ columns = [trialnum trialcode response latency values.response values.sumresponses]
</data>


By sdandeneau - 11/13/2015

Wonderful... didn't know about the "+=" function (as in values.sumresponses += values.responses). 

Thanks again!
Stéphane
By Dave - 11/14/2015

+= is the increment operator. You'll find this and all other available operators covered in the Inquisit documentation's "Operators" topic. Note, however, that one does not even need the increment operator to sum up values across trials. An equivalent way to express

values.sumresponses+=values.response

using just basic addition would be

values.sumresponses=values.sumresponses+values.response

Increment and decrement operators merely allow for more concise code.