They provide no extra functionality over variables and
exist only for convenience. Each count-expression corresponds
to an unnamed static variable, so they retain their underlying
value from call to call. Every place a count expression is
used has a unique underlying variable.
This can be used for many things, but it is mainly here
to help streamline the addition of variety to object direction,
because most of AGAST script coding is directly related to
creative writing, and not complex programmatic logic.
It's easiest to explain by example:
event Talkto -> WOLF
{
switch upcounter(10) {
case 0: "My, Granny, what big eyes you have."
case 1: "My, Granny, what big ears you have."
case 2: "My, Granny, what big teeth you have."
case 3: WOLF: "Alright already, so I'm a wolf, Sherlock."
"Big hairy deal."
default: turn(6); // face audience
"I'm not talking to him anymore."
"He'd probably just eat me."
}
}
Each time the user triggers this event, a new message
will be said, until the counter reaches 5. From then
on, the default-case is taken. If the user keeps
triggering this event, the count will eventually reach
10 and stop.
If no argument is provided, the maximum value for a
positive integer (over 2 billion) will be assumed.
Down Counter
The downcounter is like the upcounter,
except it counts in reverse from the given value
downto zero, where it stops. The first evaluation
will return the same value as the argument, so
that it 3 is passed for example, it will return
3, 2, 1, 0, 0, etc.
If no argument is supplied, a value of 1 will be assumed,
effectively returning true just once.
event Lookat -> Rock
{
if downcounter(3) {
"It's just an ordinary rock."
}
else if downcounter {
"It's still just an ordinary rock."
}
else {
"Don't you ever get tired of looking at that stupid rock?"
}
}
The first three times the user looks at the rock, the first
message will appear, the next time the second, and the final
message will appear for the remaining duration of the game.
Flip Counter
The flipcounter counts forward just like the
upcounter,
but instead of reaching the upper bound, it cycles back to 0.
If no argument is passed to it, it will assume a value of 2, and
effectively return a sequence of alternating 0s and 1s.
event Lookat -> Flower
{
if flipcounter {
"She loves me."
}
else {
"She loves me not."
}
}