Navigation stuff goes here
Command groups: read
The read command is used to read one line from a table. It is often found within a repeat loop, but doesn't have to be. You can have a single read command by itself and it'll work fine.
How to specify the data in tables
A table block looks like this:
table demoTable [in random order]
value1,value2,value3,...
value1,value2,value3,...
...
end table
- Each table in a script must have a different tablename.
- The tablename may optionally be followed by ' in random order'.
- Each table may have as many rows as you want.
- Each row should have the same number of values on it.
- Values in a row may be separated by commas or by tabs but you must use the same separator throughout the entire table.
A matching read command looks like this:
read variablename1, variablename2, variablename3, ... from table demoTable
If the read command has more variablenames than there are values on that row of the table, PsyScript will generate an error message and halt the script.
If ' in random order' is specified after the tablename, read commands return the rows in a random order. If not, the rows are returned in the order they are listed in the table, top to bottom. For more details on this, see randomness.
Here is an example of typical use of a table:
proc runTrials
declare $varImageFile
declare $varSoundFile
declare $varCorrectAnswer
repeat 4 times
read $varImageFile,$varSoundFile,$varCorrectAnswer from table stimfiles
load cell C with image $varImageFile
load cell S with sound $varSoundFile
show cell C
play sound in cell S
hide cell C
wait for a key in yn
log $varImageFile
log $varSoundFile
log $lastKey
log $lastKeyTime
log $varCorrectAnswer
if $lastKey is $varCorrectAnswer
log right
log 1
else
log wrong
log 0
end if
log $return
wait for 5 seconds
end repeat
end proc
table stimfiles in random order
horsePicture.png,catSound.mp3,n
dogPicture.png,dogSound.mp3,y
goosePicture.png,gooseSound.mp3,y
giraffePicture.png,bearSound.mp3,n
end table
Commands
read variablename1, variablename2, … from table tablename
Reads a row from the indicated table, first value into the first variable, second value into the second variable, etc..
read $varStimulusFileName from table stimuli
read $varThisSound,$varThatSound from table annoyedGrowls
reset table tablename
Returns a table to a state as if nothing had been read from it. Causes PsyScript to forget any information it's keeping about using different lines with equal frequency.
reset table stimuli
reset table annoyedGrowls
Technical notes
See also