Passing in an array of counters

I have a script that I want to write. I want from a master script to call a helper script and pass in an array of numbers. In the helper script I want to process the array of numbers, and type DownArrow the number of times represented by the value in the array. For example:

put (1,3,4) into myarray
DoIt myarray

DoIt should:
type DownArrow
type DownArrow, DownArrow, DownArrow
type DownArrow, DownArrow, DownArrow, DownArrow

I cant seem to get the syntax just right:


repeat with each column in columns
	repeat until column is 0
		typetext DownArrow
		subtract 1 from column 
	end repeat	
end repeat

I got an error when I try and subtract from my counter, saying the value is not a number.

Any advice?

You’ll need to declare the incoming parameter in your DoIt script using params. So the DoIt script might look like this:

params columns

repeat with each column in columns
    repeat column times
        TypeText downArrow
    end repeat
end repeat

See if that works better for you.

Ah yes, I am doing that, I only pasted in part of the script. The problem I think is that its not recognizing its as a number.

When I tried “repeat column times” it said

STInvalidNumberException:
Value is not a number: ‘columns’

Something doesn’t seem quite right there. Double-check that you’ve spelled everything correctly and aren’t mixing up “column” and “columns” anywhere. If your DoIt.script looks exactly like the code I posted last, and you call it like this it should work:

put (1,3,4) into myarray 
DoIt myarray

If that doesn’t seem to work for you, try stepping through in debug mode to see exactly what you’re getting in your variables.

I gave it a second look, and it was user error the second time. I hadnt declared columns in my params statement so it was null, or something. Its working fine now, thanks!