| iMatix home page
| Libero home page | Libero documentation
| << | < | > | >>
Libero Libero
Version 2.32

Dialogs For Dummies

Explain It Like I'm 5 Years Old

You've gone through all the examples and still you can't quite get your mind around the concepts? Don't worry, this is normal. It's like anything new -- it takes a while for your brain to change shape.

So far, we have seen fairly realistic examples - depending on how much booze was consumed for lunch, admittedly. Sometimes it helps to look at the entire issue from other angles. So, here is a small piece extracted from our Liberzine Liberetto I/3. Our correspondent, Big Al, writes...

iMatix asked me to write a small piece on how I learnt to use Libero. After a short discussion about fees and expenses, I quickly learnt to use Libero, applying the principle 'imagine I am a child of 5'. "No, don't try to interest me in plastic bunnies. Explain Libero to me." "Right, kids, get into two groups. You lot sit there, and you lot sit there. Now, we'll play a game..."

The first group of kids sit around a large playing board, marked with a large 'START' square, and paths that twist around. Some end in the Snake Pit, others die horrible deaths in the Bathtime Room. Just one path leads through all the dangers to the Cookie Room. The aim of the game is to get to the Cookie Room, of course. Let's look at the START square. You are in a small room. Twisty passages lead left, right, north, and south. You are holding a candle. There is a small breeze coming from the west. The floor is blue. Blue? Yeah.

The second group of kids have three or four funny dice. Each die is a different colour, with size sides. The blue die says 'Left', 'Right', 'Forwards', 'Backwards', 'Roll Again', and 'Bathtime'. The red die says 'Fight', 'Run', 'Get Eaten', 'Eat it', 'Order a taxi', and 'Bathtime'. (You gotta know how to *really* scare a five-year old.)

The rules are simple. The first group of kids just shout a colour. The second group of kids roll the matching die and - after puzzling over the letters a while - shout out what the die says. Each time the die rolls, the first group move their piece along the board to a new square.

You start to see the balance of the game. Neither group of children controls the game, it moves step-by-step until the piece wins or loses. The two groups only communicate by exchanging colours and results. Well, this is Libero. Colours are actions, results are events. And that was the easiest lunch I ever earned.

A Bit Of Animation

Sometimes it's hard to mentally connect the dialog to the running program. On the one hand you have the dry, pedantic dialog with its events and states; on the other hand you have a real live program that is actually doing something. A good way to join these two concepts is the -animate option. Use this when you generate code, and you get a display of the dialog steps a program runs through.

The examples archive has a set of programs that work out the value of arithmetic expressions. This is what one of these looks like as it works out the value of '1 + 1':

After-Init:
    (--) Ok-Event                       We just started
          + Get-Next-Token                so we collect the next token

Expecting-Operand:
    (--) Number-Event                   We got the first '1'
          + Stack-The-Number            Stick it on the operand stack
          + Get-Next-Token                and get the next token

Expecting-Operator:
    (--) Term-Op-Event                  We got the '+'
          + Unstack-Ge-Operators        Do any higher-priority operators
          + Stack-The-Operator            then stick the '+' on the stack
          + Get-Next-Token                and get the next token

Expecting-Operand:
    (--) Number-Event                   We got the second '1'
          + Stack-The-Number            Stick it on the operand stack
          + Get-Next-Token                and get the next token

Expecting-Operator:
    (--) End-Mark-Event                 We hit the end of the expression
          + Unstack-All-Operators       Do all operators on the stack
          + Unstack-If-End-Mark         The operand stack holds the result
2                                       This is displayed by the program
          + Terminate-The-Program       End and return to the caller

| << | < | > | >>
| Introduction to Libero | The Coke Machine Example | Example of Using a Telephone | Example of Controlling a Telephone | Source Code For Phone.c | Example of a C/C++ Comment Stripper | Example of Parsing An Arithmetic Expression | Dialogs For Dummies | Frequently Asked Questions
iMatix
Copyright © 1996-97 iMatix