Variables are used when you have a value which you may want to use sometime later. You can think of a variable as a pigeonhole big enough for one value, or as a line on a big ruled notepad. PsyScript includes instructions for declaring a variable (the declare command), setting the value of a variable (the set command, the set command for arrays), noting the value of a variable in the session's log file (the log command), and for doing various different things depending on the value of a variable (if, while, repeat, etc.).
In PsyScript, all variables contain text: zero or more characters. Some of those characters may look like numbers, e.g. the string '1' or the string '-23.345', but PsyScript doesn't understand that value as a number. It can't do calculations with it, or compare one number with another and see which is greater.
PsyScript automatically declares and sets the following variables itself:
$blank, $space, $tab, $return
$dateStamp, $timeStamp, $random5
$lastEventEnder, $lastEventTime
$lastClick, $lastClickXCoord, $lastClickYCoord
$lastKey
$lastResponses
$cellValueA, $cellValueB, $cellValueC, …
$timerTime, $countdownTime
PsyScript returns values for these variables as it sees fit. You cannot set the values of these variables yourself. Most of them are obvious or are documented on the page about the PsyScript command that sets them, but here are two that aren't:
As well as the pre-declared variables described above, you declare any number of variables yourself. Once such a variable is declared you can use some set commands for strings and set commands for arrays.
PsyScript includes some commands which manipulate variables as if they're arrays. They're handled internally as strings of characters separated by the | (pipe) character. So a string containing pat|harry|elizabeth will be seen as a three-element array by some commands. You can set a value as a string, but examine it later as if it's an array, or vice versa. There are some set commands for arrays.
Before understanding this section you must understand procedures.
It can sometimes be useful for a procedure to have a private variable: one it knows won't interfere with anything done outside that procedure. The 'scope' of a variable describes where the variable can be accessed or 'seen' from. In PsyScript the scope of a variable is the procedure it was declared in, plus any procedure called by that procedure. The end proc for the procedure a variable was declared in deletes the variable. In illustration …
If a variable already exists when a procedure is called, a new variable with the same name can be declared in that procedure. If this is done, the new variable 'obscures' the original one until the new variable is destroyed. References to that variable name inside the called procedure will see the new 'inner' variable, not the old 'outer' one …
As the called procedure returns control to the procedure which called it, the second variable is deleted and the original variable becomes visible again.
Lastly, it is an error to declare the same variable twice in the same procedure …
the idea of variable scope comes from traditional programming languages and can be complicated. If you don't want to deal with it, declare all your variables just once, immediately after the beginning of the 'main' procedure, and you will be able to access them anywhere in your script.
All variables in PsyScript contain strings. PsyScript can keep numbers in variables as a few digits with perhaps a minus-sign or a decimal point, but it doesn't understand that they are numbers. An early version of PsyScript understood numbers. It could do (primitive) maths on them and it could compare one with another. I had to remove this feature.
The problem was that users were processing their experimental results inside PsyScript, processing their participants reactions and logging their averages and variances inside the experiment log. That's not a problem. The problem was that because they could draw conclusions they did not log their participants' responses to the stimuli, just the analysis. Their entire log for the experiment might read something like "female, 18-22 years, 8 correct, 2 wrong". Since experimenters had no record of participant action, their experiments were useless for anyone trying to analyse responses in a new way, and their write-ups were attacked on the grounds that they were unable to produce any log of what went on during an experiment.
PsyScript is intended to be experiment conducting and logging software, not analysis software. It was clearly failing in its job. So I had to remove these abilities. Use PsyScript to conduct your experiment and note what your partipant did. Once your experiment is over, then you can use spreadsheet or numerical analysis software to analyse the results.