Here is one of my favorite gadgets to play with arrays. It counts things, like the occurrences of words in a body of text.
On a new card, make a button and a field. In the field, put something like:
cat dog cat hippo mouse mouseUp donkey ibis cat ibis ibis ibis dog monkey
In the button script:
Code: Select all
on mouseUp
get fld 1
--breakpoint -- enable here when ready
repeat for each word tWord in it
add 1 to animalCount[tWord]
end repeat
combine animalCount by return and comma
answer animalCount
end mouseUp
If you step through the code by enabling the breakpoint, you can see the development of the array variable "animalCount". Remember to "open" the contents of the array in the debugger while stepping through.
This is also useful in knowing that the debugger is an excellent place to be able to see an array variable without having to change it into an ordinary variable, using the "combine" command above. An array is normally not visible in the real world.
Craig Newman
EDIT: Moved breakpoint to the correct place in the handler.