|
ANY-maze Help > The ANY-maze reference > The Protocol page > The elements of a protocol > Testing > Procedures > Elements of a procedure > Statements available to procedures > Other statements Other statements
IntroductionAlong with the basic statements that are the building blocks of all procedures, there are some more esoteric statements that are used in more advanced procedures. Most of these statements are to add useful functionality when working with user-defined variables, particularly variables that are an array of values. The functions covered in this topic are as follows:
The Initialise array statementThe Initialise array statement is a simple way to set up the different elements of an array variable without needing to set up a loop. The values for the array are entered separated by commas. The following example initialises an array variable with 5 values to contain the values 1000, 2000, 3000, 4000 and 5000 in numerical order. These will be used later as tone frequencies to play through an AMi's speaker.
Figure 1. Using the Initialise array statement to set up the values of an array variable.
If there are more comma-separated values than the array will hold, any extra values will be ignored. If there are fewer values than the array will hold, the other values will be set to zero.
The Initialise array statement can be used at any point in a procedure, and doesn't necessarily have to be used at the start.
An array variable can be initialised to anything that can be represented as text - a numerical value as in figure 1 above, text itself, or True/False values. The following example demonstrates setting up an array with some True/False values, and another array with some names.
Figure 2. Using the Initialise array statement to set up the values of an array variable.
If you need to set up an array to contain something other than numbers, text, or True/False values (for example, positions of a movable zone) then simply enter the names of these as text. ANY-maze can convert names to the relevant zone position when needed.
The Randomise array statementOn occasions, the values in an array will need to be initialised to a random, rather than a pre-defined, order. Let's assume that you want the tone frequencies in the above example to be played in a random order; you would use the Randomise array statement to put them in a random order:
Figure 3. Using the Randomise array statement to change the values in the array from figure 1 to a random order.
The resulting array will now contain the values in a random order (e.g. 2000, 5000, 1000, 4000, 3000).
Randomising an array, with a maximum number of consecutive valuesThere is a second variant of the 'Randomize array' function which allows you to specify the maximum number of elements that can be repeated. For example, you may wish to randomize whether it is the left-hand nose poke or right-hand nose poke that dispenses a reward, and you want a total of 50 rewards - but you don't want more than three consecutive rewards to be on the same side. In this case, you would set up the array with 25 'Left and 25 'Right' values, and use the 'Randomise array' variant that allows you to specify a maximum number of repeats. You would specify this maximum number of repeats as 3. This would ensure, for example, that the randomisation did not allow 'Left, Right, Left, Left, Left, Left, Right...' since this would mean that there were more than three consecutive 'Left' values in the array. If you specify a maximum repeat count, but ANY-maze cannot randomize the values without finding more than this number of repeated values, then a run-time error will occur. If you want to simply generate a single random number, see the Random function under Maths functions and operators. The Sort array statementThis function will take an array and sort all its values into ascending order. This will be in ascending numerical or alphabetical order:
Figure 4. Sorting the contents of the array variable randomised in Figure 3 into ascending order.
After sorting, the array will contain the values in ascending order (i.e. 1000, 2000, 3000, 4000, 5000). If the array contains True/False values, then all 'False' values will be sorted before the 'True' values. The Copy array statementThis statement copies the contents of one array to another.
Figure 5. Copying the contents of an array variable into a different array variable.
If the array being copied is larger than the array it's being copied to, then the extra values will be ignored and not copied. If the array being copied is smaller than the one it's being copied to, then the extra array indexes will still contain their previous values.
The Set to #N/A statementIf you're using a variable within a procedure to measure a specific value, what happens if the thing you're measuring never happens? For example, you might be measuring the number of times that the animal was grooming while in a specific zone. But what happens if the animal never enters the zone? You probably wouldn't want to record the value as zero, because that doesn't tell you whether the animal entered the zone and never groomed itself, or whether it never entered the zone at all. The value #N/A is used for just such a purpose. N/A stands for 'Not available' and can be used to differentiate a result from zero.
Figure 6. Initialising the value of a variable to #N/A.
You can use the Is undefined function to test whether the value of a variable is #N/A.
See also:
© Copyright 2003-2026 Stoelting Co. All rights reserved ANY-maze help topic T0487 |