Operators

Inquisit expressions supports all of the basic operators for doing arithmetic, comparing values, and creating logical statements. The complete list of operators and their syntax is listed below.

Arithmetic Operators

Arithmetic operators are used to perform additional, subtraction, multiplication, and division.

Operator Description Examples
+ Adds numeric operands or concatenates two or more strings.

trial.condition1.correctcount + trial.condition2.correctcount

values.firstscore + values.secondscore

response.rw.windowcenter + 500

- Subtracts numeric operands.

100 - trial.mytrial.percentcorrect

block.incompat.meanlatency - block.compat.meanlatency

* Multiplies numeric operands.

trial.test.correctcount * 5

trial.test.trialcount * trial.test.meanlatency

/ Divides numeric operands.

trial.mytrial.percentcorrect / 100

block.myblock.sumlatency / block.myblock.trialcount

+= Adds the value of an expression to the value of a variable and assigns the result to the variable.

values.trialcount += 1

values.totalfalsealarms += values.falsealarmcount

-= Subtracts the value of an expression to the value of a variable and assigns the result to the variable.

values.remainingtrialcount -= 1

values.totalpoints -= values.errorcount

Comparison Operators

Comparison operators compare the values of the right and left operands and return a Boolean value of true or false.

Operator Description Examples
== True if the right and left values are equal. Otherwise false.

trial.iat.trialcount == 100

block.compat.percentcorrect == 0

trial.foo.correct == 1

!= True if the left and right values are not equal. Otherwise false.

trial.iat.trialcount != 1

block.compat.percentcorrect != 100

response.rw.windowcenter != 0

< True if the left value is less than the right. Otherwise false.

trial.iat.trialcount < 25

block.compat.percentcorrect < 100

trial.test.latency < 500

<= True if the left value is less than or equal to the right. Otherwise false.

trial.iat.trialcount <= 25

block.compat.percentcorrect <= 100

trial.test.latency <= 500

> True if the left value is greater than the right. Otherwise false.

trial.iat.currenttrialnumber > 25

block.compat.percentcorrect > 50

trial.test.latency > 500

>= True if the left value is greater than or equal to the right. Otherwise false.

trial.iat.currenttrialnumber >= 25

block.compat.percentcorrect >= 50

trial.test.latency >= 500

Assignment Operator

The assigment operator assigns a value to a property. Note that the operand on the left must be a writable property. Many properties (computer.cpuspeed, for example) are read-only values that can not be changed. An expression that attempts to assign a value to a read-only property will fail.

Operator Description Examples
= Sets the value of the left operand to that of the right.

items.targets.item.1 = trial.gettargets.response

response.rw.windowcenter = response.rw.windowcenter - 100

values.score = trial.game.correctcount * 5

Logical Operators

Logical operators return true or false depending on whether the operands are true or false. These operators are especially useful in conditional if-else statements that involve multiple conditions.

Operator Description Examples
&& Logical AND. True if both the left AND right operators are true. False if either operand is false.

if (block.test1.percentcorrect == 100 && block.test2.percentcorrect == 100) values.perfectscore = true

if (block.test.percentcorrect < 70 && block.test.medianlatency > 500) response.rw.windowcenter = 600

|| Logical OR. True if either the left OR right operand is true. False if both operands are false.

if (block.test1.percentcorrect < 100 || block.test2.percentcorrect < 100) values.perfectscore = false

if (trial.test.latency < 100 || trial.test.latency > 1000) values.discard = true

! Logical NOT. True if the operand is NOT true. False if the operand is NOT false. values.imperfect = !values.perfect

Conditional Statements

Conditional statements consist of two parts, a condition that evaluates to true or false, and a statement that is evaluated if the condition part is true. Conditional statements are often referred to as "if-else" statements. These are useful for event logic that conditionally updates values. They are also used by the branch attribute to determine whether any branching should occur.

Statement Description Examples
if ... else ... If the condition is true, then evaluate the first statement, otherwise evaluate the second statement.

if (block.test1.percentcorrect == 100 && block.test2.percentcorrect == 100) values.perfectscore = true

if (block.test.percentcorrect < 70 && block.test.medianlatency > 500) response.rw.windowcenter = 600

if (block.test1.percentcorrect < 100 || block.test2.percentcorrect < 100) values.perfectscore = false else values.perfectscore = true

Precedence and Grouping

You can use parentheses to set the order in which operations are applied, or to make your statements easier to read.

Delimiter Description Examples
() Contains a set of statements that should be evaluated as a unit.

values.imperfect = (trial.test2.sumlatency + trial.test1.sumlatency) / (trial.test2.trialcount + trial.test1.trialcount)

Multiple Statements

Multiple statements can be expressed in event logic by separating each statement with a semi-colon.

Delimiter Description Examples
; Delimiter for multiple statements

values.imperfect = !values.perfect; items.targets.item.1 = trial.gettargets.response; values.score = trial.game.correctcount * 5