Compound Parts - PAT:TEXT

Here's a simple demonstration of a part that will accept text, store it in a variable, and return the text focus back to the game.

new: comp 1 11 1234 "smalltextbox" 1 0 9000Create a new compound object (you should know the rest by now!)
attr 38Give it attributes (check the CAOS Language Guide if unsure of what this mean)
pat: text 1 "smalltextbox" 1 10 5 0 1000 "blackonwhitechars"Create part 1 - a text entry part. Use the sprite file called 'smalltextbox' starting at frame 1. Offset this part by (10,5) in relation to part 0. When text is entered this will trigger event 1000. Use the specified font file.
flto 600 300Float to this position on screen
scrp 1 11 1234 1000The event 1000 for this agent
part 1Change to part 1 ...
sets ov00 ptxt... and store the text on it in OV00
targ game "c3_default_focus"Change targ to the agent specified by this game variable ...
part game "c3_default_focus_part"and change part to the part specified by this game variable ...
fcus... and give it the focus

The only part of this that should need explaining is the use of game variables here. There can only be one agent at a time that has the focus for the keyboard, and during normal play this is the agent that is responsible for producing speech bubbles from the hand. When this agent was created it also created a new game variable (there is more information about game variables in a different section) specifically to store its agent ID and the relevant part number. Uses a game variable for this means you don't have to remember the specific agent concerned (although you do have to remember the name of the game variable!). If you try and create a text entry agent without returning focus back to the 'c3_default_focus' object you will find that you can no longer make words appear from the hand.