Parameters are declared within the <parameters> element and are generally used for settings that change the behavior of a script. They are global variables that can be used anywhere in the script including the <data> element. Parameters provide a way to quickly and easily change your experiment such as timeouts, stimuli sizing, trial numbers, and response key assignments amongst many others. Parameters can be referenced as parameters.xxx.
The following example declares and stores parameters.testTimeOutMS to the raw data file.
<parameters> / testTimeOutMS = 900000 //15 minutes </parameters>
<data> / columns = (date, time, subject, group, parameters.testTimeOutMS, blockcode, trialcode, response, latency) </data>
Values are declared within the <values> element. They are global variables in Inquisit scripts that can be accessed from anywhere in the script, including the <data> element. In contrast to parameters, values are generally used for variables whose values are expected to change throughout runtime of the script. Variables declared under a <values> element can be referenced as values.xxx.
The following example declares values.winAmount and updates it at the end of trial.choice based on accuracy performance.
<values> / winAmount = 0 </values>
<trial> / stimulusTimes = [0 = choiceA, choiceB] / validResponse = (choiceA, choiceB) / correctResponse = (choiceB) / onTrialEnd = { values.winAmount += this.correct; } </trial>
Variables can be declared within a script using the JavaScript var statement. With the exception of variables declared in the <script> element (see below), variables are scoped locally to the script block where they are declared. Local variables are useful for storing values used in local calculations that do not need to be accessible throughout the script. They can be declared on the spot without needing a specialized element to do so and are simply referenced by their name.
The following example uses a var repeatLoops that is only needed for one particular while loop. Its value is not important for any other aspects of the script, and thus it is not retained outside of the onTrialBegin attribute of trial.looping.
<trial looping>
/ onTrialBegin = {
var repeatLoop = true;
while (repeatLoop){
if (list.latencies.nextValue > parameters.maxAllowedRT || list.latencies.unselectedCount <= 0){
repeatLoop = false //we have reached the end for the loop
} else
values.validResponseTimeCounter ++;
}
}
}
/ stimulusFrames = [1 = validResponseCounts]
/ validResponse = (" ")
</trial>
Variables declared within the <script> element are globally accessible throughout the script. These variables can be referenced throughout the script, although they can not be listed in the columns for data elements, and thus can neither be stored directly in the raw nor summary data files.
In the following example var winAmount is declared directly under a <script> element. It can thus be used and changed throughout the script but it cannot be saved to the data files.
<script> var winAmount = 10; </script>
Local variables can also be declared using the JavaScript let keyword, which is considered a safer choice than using "var" in JavaScript programming. let variables are declared the same way as var variables. However, whereas var variables have function scope and can be accessed anywhere within a function, let variables have block scope so are only accessible within their script block. They cannot be saved to the data files in Inquisit scripts.
In the following example, we declare a local variable winAmount using the let keyword.
<trial myTrial>
/ onTrialBegin = {
let winAmount = 3; //local variable 'winAmount' can now be used throughout this onTrialBegin attribute
winAmount++; //winAmount is now set to 4
}
/ trialDuration = 0
/ onTrialEnd = {
values.totalAmount = 10 + winAmount; //this code will result in an error: local variable 'winAmount' is not accessible in this 'onTrialEnd' attribute
}
</trial>