Using Text in Director
There are two types of cast members for using text: "Text" and "Field". Both can be used for static text, editable text for input, and text that is changed from lingo for output. Both can use different fonts, colors, and styles.
With Text Cast Members, you can:
- use multiple fonts in one piece of text, and change them from lingo
- display anti-aliased (smooth) fonts
- use 3D styles
- use hypertext styles
- create text hyperlinks
Field cast members have fewer formatting options, but can be drawn with framing and shadowing. They are often used for quick input boxes..
Editable Text
to make a text member editable, check the "editable" box in the property inspector.
The Text Inspector
for quick access to formatting controls: Window->Inspectors->Text Inspector
Embedding Fonts
Director relies on the fonts installed on the user's computer. If someone runs your projector or Shockwave file but doesn't have the necessary fonts, the text will show up using a default system font. To include fonts with a projector or shockwave, embed them:
Insert->Media Element->Font
pick the font you want to embed (for example
"Sand")
give your embedded font a name (it will default to "*
original font name", e.g. "* Sand" or "* Edwardian
Script".
your embedded font will show up in the list of fonts when setting text formatting.
embedding bitmaps for font sizes will make those sizes display better, but increases the file size. also, if you're only using a few character from a font, you can embed a partial set of just those characters to save space.
Manipulating Text from Lingo
a piece of text is often called a string. a string can be anything from a single letter to whole document.
getting a string out of a text cast member:
t=member(1).text
putting a string into a text cast member
member(1).text
= "hello world"
or
put
"hello world" into member(1)
inserting at the beginning or the end:
put
"hello" after member(1)
put
"hello" before member(1)
example:
put
"morning" into member(1)
put
"good " before member(1)
put "
sunshine" after member(1)
accessing a single character, word, or
line:
characters, words, and lines are just
Lists attached onto text cast members or onto other strings.
x=member(1).char[10] --10th
character in member 1
x=member(1).word[3] -- 3rd word
x=member(1).line[2] -- whole 2nd line
changing words, characters, etc.
member(1).text
= "good morning"
member(1).word[2]
= "afternoon"
counting words, characters, lines:
wordcount
= member(1).word.count
charcount
= member(1).char.count
Repeat Loops
loops are another programming technique
common to almost all languages. A
loop is a way of telling the program to repeat a section of code a specified
number of times. Autu-Animation
scripts using exitframe handlers are a type of loop, because they are designed
to run over and over again to move a sprite. You can also build a loop in lingo using the repeat command:
repeat
with variable = start to end
some lingo
commands
end repeat
variable is a variable that will be used to control the loop. it counts from start to end.
for instance, to print out
"hello" ten times:
repeat
with i=1 to 10
put
"hello"
end repeat
i is a commonly used loop variable name, but you can use any
variable name you want.
you don't have to set the variable to
anything - it starts out being set to the start value (in
this case, 1).
you can also make the commands inside the
loop do different things each time:
-- 20
random numbers, each from 1 to 100
repeat
with i = 1 to 20
r = random(100)
put r
end repeat
many loops use the counter variable to do
different things:
--print
out numbers from 1 to 10
repeat
with i = 1 to 10
put i
end repeat
you can do quick animations as well:
-- move
sprite 1 across the stage
repeat
with x = 1 to 320
sprite(1).loch = x
updatestage
end repeat
the updatestage command forces the sprite to draw its new position, even though
the handler hasn't ended yet. if
you leave it out, you only see the first & last positions.
Using Repeat Loops with Text Strings
repeat loops are particularly useful for
processing, manipulating, and mangling text strings.
first, a few examples of picking random
items from a string:
--random
greeting in alert
--put
greetings into text member 1, each on its own line
on mousedown
greetingCount = member("greeting
list").line.count
r = random(greetingCount)
greeting = member("greeting
list").line[r]
alert (greeting)
end
to display the greetings on the stage,
make another text member called "greeting display". put it on the stage, and put this handler
on it. the "greeting
list" member doesn't have to go on the stage at all.
--random
greeting 2
on mousedown
greetingCount = member("greeting
list").line.count
r = random(greetingCount)
greeting = member("greeting
list").line[r]
member("greeting
display").text = greeting
end
Now to use some repeat loops to make more
interesting texts:
--random
DNA code
on mousedown
letters="GATC"
letterCount =
letters.length
--use 'length' instead of 'count'
--because 'letters' is a string, not a list
member ("DNA").text = ""
repeat with i = 1 to 100
r
= random(letterCount)
put letters.char[r] after member("DNA")
end repeat
end
* Tip * To do text processing faster, process it in a temporary variable
first, then copy it into the actual cast member to display it.
--faster
random DNA code
on mousewithin
letters="GATC"
letterCount = letters.length
myGenes="" -- temp
variable
repeat with i = 1 to 100
r = random(letterCount)
put letters.char[r] after member("DNA")
end repeat
member("DNA").text
= myGenes -- copy into cast member
end
The Cut-Up Method
Do a similar process with words instead
of characters to produce Cut-Ups.
--apply
the cutup method onto a text
on mousedown
cutup =
""
wordcount =
member("original version").word.count
repeat with
i = 1 to 20
-- 20 words total
r =
random(wordcount)
nextword = member("original").word[r]
put " " & nextword after cutup --
include a space between words
end repeat
member("cutup
version").text = cutup
end
To get something a little more
comprehensible, pull phrases out of the original text instead of just
individual words. Pick a random
word, and then up to 10 words after it.
--cutup
phrases
on mousedown
cutup =
""
wordcount =
member("original version").word.count
repeat with i = 1 to 20 -- 20
words total
r =
random(wordcount)
r2 = r + random(10)
if r2 > wordcount then r2 = wordcount
phrase = member("original
version").word[r..r2] -- from r
to r2
put " " & phrase after cutup -- include a space
between words
end repeat
member("cutup
version").text = cutup
end
Codes and Ciphers
The "Magic Ring" cipher: take
each letter and add some value to it; A becomes B, B becomes C, etc. To decrypt, subtract instead of adding. In order to do this, you have to turn
the characters into numbers and back again using
charToNum()
and
numToChar()
--
encrypt
on mousedown
cipher = 1
-- amount to shift by
charCount =
member("the text").char.count
cipherText =
"" -- temporary variable
repeat with i = 1 to charCount
plainchar = member("the
text").char[i]
n =
charToNum(plaintext) -- get the character
code
n2 = n + cipher -- encrypt
cipherchar = numToChar(n2) -- turn
back into a character
cipherText = cipherText
& cipherChar -- add onto text
end repeat
member ("the text").text = cipherText
end
--
decrypt
on mousedown
cipher = 1
-- amount to shift by
charCount =
member("the text").char.count
cipherText =
"" -- temporary variable
repeat with i = 1 to charCount
plainchar = member("the
text").char[i]
n =
charToNum(plaintext) -- get the character
code
n2 = n - cipher -- encrypt
cipherchar = numToChar(n2) -- turn
back into a character
cipherText = cipherText
& cipherChar -- add onto text
end repeat
member ("the text").text = cipherText
end
Artificial Intelligence
many AI attempts are based on natural language processing, trying to make computers understand human language. ELIZA is an early experiment that simulated Rogerian Psychoanalysis, a method of analysis based on turning questions back on the patient to stimulate self-discovery. ELIZA has occasionally passed the Turing Test, meaning that it has been known to fool people into thinking it is another human.
ELIZA looks for certain words in your input text, using the contains function.
--
put this onto a button. make one
text cast member called "input",
--
one called "output", and one called "random responses".
on mousedown
input =
member("input").text
if input contains "hello"
then response = "how are you
feeling?"
else if input contains "dream"
then response = "what do you think that
dream means?"
else if input contains "computer"
then response = "do computers worry
you?"
else if input contains "you" then
response = "we're talking about you, not
me"
else if input contains "feel" then
response = "does it bother you to feel that
way?"
else if input contains "sorry"
then response = "do you have a lot of
guilt?"
else if input contains "no" then
response = "can you be more positive?"
else if input contains "?" then
response = "why do you ask that?"
else if input contains "!" then
response = "there's no need to shout."
else -- no keywords ... pick a random, general-purpose
response
linecount =
member("random responses").line.count
r =
random(linecount)
response = member("random
responses").line[r]
end if
member("output").text
= response
end
Random Responses:
Do you really think so?
Please elaborate.
Tell me more.
Can you be more specific?
What is on your mind?
That is quite interesting.
(etc).