Navigation stuff goes here


Command groups: set for arrays

PsyScript does not have a special set of variables to handle strings, it handles arrays as strings with each item preceeded by the pipe ('|') character. You can mix and match between the set command for strings and the set command for arrays in manipulating variables. For example, to set a variable to an array with three items in it you might use

set $varPlaces to |left|centre|right

which would do the same as

set array $varPlaces to left set array $varPlaces by appending centre set array $varPlaces by appending right

which would do the same as

set $varPlaces to | set $varPlaces by appending left set $varPlaces by appending | set $varPlaces by appending centre set $varPlaces by appending | set $varPlaces by appending right

which would do the same as this set command for arrays:

set array $varPlaces to left set item 3 of array $varPlaces right set item 2 of array $varPlaces to centre

The set commands for arrays are intended to help you consult and manipulate arrays more conveniently than having to specify separators yourself. As with strings, the variable you are setting must have been declared using the declare command before its value can be set or consulted.

There are five forms of the set command for arrays:

set array <variable> to <value> set array <variable> by appending <value> set item <value> of array <variable> to <value> set <variable> to the length of array <value> set <variable> to item <value> of array <value>

There's also a command which extracts the first element of an array and moves the other elements up one:

extract first item of array <value> to <value>

Lastly, there is a special version of the log command which logs an array item by item rather than as one long string with | characters in it.

Commands

set array variable to value

Replaces the existing value of the variable with a single-element array.

set array $varScoresSoFar to $blank
set array $varB to $lastClick


set array variable by appending value

Appends the new item to the end of the array.

set $varClickCellList by appending $lastClick
set array $varTimeOptions by appending fifth|sixth|seventh
set $varA by appending $varN


set item value of array variable to value

Replaces the existing value of that item of that array. If the item number is less than 1 nothing may happen. If the item number is greater than the existing length of the array, the array is extended with blank items until it's long enough to include it.

set item 3 of array $varThirdChar to Apples
set item 114 of array $varB to $lastKey


set variable to item value of array value

Replaces the existing value of the variable with one item from the array. If the item number is less than 1 or greater than the length of the array, then the result is $blank.

set $varThirdChar to item 3 of |abc|de|fgh
set $varB to item 14 of $varAllowableAnswers
set $varB to item $varAnswerNumber of $varAllowableAnswers


set variable to the length of array value

Finds the number of items in the array.

set $varNumberOfKeys to the length of array $varKeysSoFar


extract first item of array variable to variable

Extracts the first element of an array and moves the other elements up one. If the value supplied for the array has no elements or is not an array weird things may happen. Note that this command changes both variables mentioned: the individual item and the array.

extract first item of array $varKeyList to $varThisKey

Technical notes

See also