Millisecond Forums

solution to multiple if statements not working

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

By thv - 10/3/2016

Hello,
I ran into issues using multiple if statements in inquisit version 4 that I solved myself, but could not find the solution documented anywhere, so I thought I'd share.

When using multiple if statements in, for example, ontrialend, they cannot all be placed in the same on trial end section or else I believe only the first will run.
ie. this will NOT work:
/ ontrialend = [
if (correct==1) {values.response = 1}
else {values.response = 2}

if (latency > values.resp_window) {values.inwindow = 0;}
else {values.inwindow = 1;}
]

Instead they must be placed in separate ontrialend sections:

/ ontrialend = [
if (correct==1) {values.response = 1}
else {values.response = 2} 
]
/ ontrialend = [
if (latency > values.resp_window) {values.inwindow = 0;}
else {values.inwindow = 1;}
]

By Dave - 10/3/2016

> ie. this will NOT work:

> / ontrialend = [
> if (correct==1) {values.response = 1}
> else {values.response = 2}
>
> if (latency > values.resp_window) {values.inwindow = 0;}
> else {values.inwindow = 1;}
> ]

The above doesn't work because the statements aren't properly separated, i.e., the syntax is wrong. Do


/ ontrialend = [
if (correct==1) {values.response = 1}
else {values.response = 2} ; <-Semicolon is the separator

if (latency > values.resp_window) {values.inwindow = 0;}
else {values.inwindow = 1;}
]

and it should work just fine.

See for yourself by running

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

<trial mytrial>
/ ontrialend = [if (values.a) {values.response = 1}
else {values.response = 2};
if (values.b > values.c) {values.inwindow = 0;}
else {values.inwindow = 1;}
]
/ validresponse = (57)
</trial>

<values>
/ a = false
/ b = 3
/ c = 4
/ response = 0
/ inwindow = -1
</values>

<data>
/ columns = [values.a, values.b, values.c, values.response, values.inwindow]
/ separatefiles = true
</data>

which has the same structure as your logic.