solution to multiple if statements not working


Author
Message
thv
thv
Esteemed Member (1.9K reputation)Esteemed Member (1.9K reputation)Esteemed Member (1.9K reputation)Esteemed Member (1.9K reputation)Esteemed Member (1.9K reputation)Esteemed Member (1.9K reputation)Esteemed Member (1.9K reputation)Esteemed Member (1.9K reputation)Esteemed Member (1.9K reputation)
Group: Forum Members
Posts: 23, Visits: 73
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;}
]


Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 12K, Visits: 98K
> 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.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search