Here is the function
ros code
# Usage: [$arrayPush <array name> <value>] # Input an array name and a value to push to the end of the array :global arrayPush do={ :if ($1="") do={ :error "You did not specify an array name argument."; } :if ($2="") do={ :error "You did not specify a value to add to the array."; } :local string; :if ([:typeof $1]="array") do={ :foreach item in=$1 do={ :set string ($string . "," . $item); } :set string ($string . "," . $2); :set string [:toarray $string]; :return $string; } else={ :error "Argument 1 variable type was not an array."; } }Here is an example of what I mean
ros code
:global myVar; :set myVar [:toarray $myVar]; :set myVar [$arrayPush $myVar "some value"];Since $myVar is nil, the toarray function essentially does nothing and the next line has undesired results. I'm not sure exactly how to explain this but hopefully you get the picture. Any ideas on a way to work around this?
The only thing I can currently think of is to test if the array exists before I initially call the function and if not, create a variable as a string, then convert it to an array but that's a lot of extra steps.