Aside from their interactive text-entry function, fields can be extremely useful as "storage containers" for temporarily holding, accumulating, or transferring data in the form of words or numbers.
To create a storage field, select a castmember slot, go under the "Insert" menu heading to "Control" to "Field". An empty field member will be created in the cast, score, and stage. Unless you need it delete the entry in the score. "Get Info" for the castmember field and give it a simple relevant name (eg. "sounds"). Here is also where you can make it editable, if you ever want to.
Entries in fields are called "strings" which are simply any set of characters, words, letters, or numbers (integers) separated by spaces and surrounded by quotation marks. For example, these are all strings:
"x y z" "boom whoosh scratch" "have a nice day" or "1 4 6 7 12"
By using the: "put "boom whoosh scratch" into field "sounds"" command from a movie, frame, or button script (or the Message window) you can input relevant data to begin to use your new field. By typing the command: "put field "sounds" in the message window you can 'test' to return the 'value' (contents) of your field. In this case it would be "boom whoosh scratch". This is really much easier than it sounds.
For instance, you can put the names (or numbers) of sound, graphic, or text castmembers scattered through the cast into a field, and then randomize their use from that field. For an extended example of this, examine the included scripts that follow.
You can add single items or the contents of one field to another existing field using the command: put "thud" after (or before) field "sounds" or: put field "sounds2 after field "sounds.
By using a script like:
put the clickOn (or memberNum of the clickOn) into field "tattooChoice"
global gfield "tattooChoice"
you can store the identity of a sprite or castmember for later access, even across a linked movie.
Fields can be used to search or compare the contents of other fields as in:
on keyDown
if the key = return then memorySort
end keyDownon memorySort
put the number of words of field "memoryEntry" into n
repeat with i = 1 to n
if word i of field "memoryEntry" = "water" then jar1
else
if word i of field "memoryEntry" = "flying" then jar2
else nothing
end if
end repeat
end on memorySorton jar1
play movie "drowningDream"
put field "memoryEntry" after field "MemDataBase"
end jar1
Lists can be much more complex, but can be set up and used in similar logical fashion to fields, as in:
set ListA = ["rockFishJar", "quartzJar", "spiderFish", "rockFish"]
to hold multiple values stored as a single variable. These can be accessed individually, multiply, or randomly to define various handler actions, as in:
put count(ListA) into x - (counts # of elements, stores # in x)
set rock = getAt(ListA, random(x))
As you begin to understand the logic within field and list scripts, they will become much easier to read and write - but be patient! Don't worry if you don't get the lingo just right the first few times.
The following are some very basic field scripts useful for storage, randomizing, etc. They also contain some useful tidbits for puppetting, depuppeting, timing, mouseCast, visibles, etc. Make sure to look at the demo movie that uses the following movie script and cast field usage, as well as the frame and button scripts. Deceptively simple . . .
on startMovie
put "Whistle Bugle Clank Gliss Axed" into field "sounds"
put "9 10 11 12" into field "switchCast"
put "Chirp Moo Photon Train" into field "track"
put "31 32 33 34 " into field "switchCast2"
put field "switchCast" after field "switchCast2"
end on startMovieon idle
put word random(4) of field "track" into field "secondSound"
end on idle
on enterFrame
repeat with channel = 1 to 5
puppetSprite channel, TRUE
end repeat
case the rollOver of
2: earMix
3: earMix
4: earMix
5: earMix
otherwise nothing
end case --sprite 1 is set to copy ink
if rollOver (1) then swap
else cleanUp
end on enterFrame--Done earlier in movie script:
--put "Whistle Bugle Clank Gliss Axed" into field "sounds"
on earMix
puppetSound word random(5) of field "sounds"
updateStage
end earMix
--Done earlier in movie script:
--put "9 10 11 12" into field "switchCast"
on swap
set n = integer(word random(4) of field "switchCast")
set the memberNum of sprite 1 to n
updateStage
end swap
on cleanUp
set the memberNum of sprite 1 to 1
updateStage
end cleanUp
on exitFrame
go to the frame
end exitFrame
on mouseUp
repeat with channel = 1 to 5
puppetSprite channel, FALSE
end repeat
puppetSound 0
puppetTransition 52, 4,10
go to frame "matte/mouse"
end
on enterFrame
repeat with channel = 1 to 5
puppetSprite channel, TRUE
end repeat
case the rollOver of
2: earTwo
3: earTwo
4: earTwo
5: earTwo
otherwise nothing
end case
--sprite 1 is set to matte ink.
--Using mouseCast with matte ink more accurate than rollOver
if the mouseCast = 1 then swap
else cleanUp
end on enterFrame
--Done earlier in movie script:
--put "Chirp Moo Photon Train" into field "track".
--on idle - put word random(4) of field "track"
--into field "secondSound" - end on idleon earTwo
puppetSound word 1 of field "secondSound"
updateStage
end earTwo--Done earlier in movie script:
--put "31 32 33 34 " into field "switchCast2"
--(notice extra space after 34 " - allows next correctly:)
--put field "switchCast" after field "switchCast2"
--Test: put field "switchCast2" - "31 32 33 34 9 10 11 12"on swap
cursor 3
set n2 = integer(word random(8) of field "switchCast2")
set the memberNum of sprite 1 to n2
updateStage
end swapon cleanUp
cursor -1
set the memberNum of sprite 1 to 1
updateStage
end cleanUpon exitFrame
go to the frame
end exitFrame
on mouseUp
repeat with channel = 1 to 5
puppetSprite channel, FALSE
end repeat
puppetSound 0
go to frame "invis"
end
on exitFrame
cursor 200
puppetSprite 1, TRUE
set the visible of sprite 1 = FALSE
end
on exitFrame
cursor 0
set the visible of sprite 1 = TRUE
go to frame "start"
end