Language

From Pry
Revision as of 13:19, 18 May 2025 by Admin (talk | contribs) (→‎Stack)
Jump to navigation Jump to search

Language basics

The language used in Pry with AI is called GameLoops. A game consists of one more game loops, and each game loops contains one or more commands, like:

DISPLAY "Hello world!"

By convention command names are written with capitals. All command parameters should be quoted, being formally strings of characters (texts).

Stack

The key concept in GameLoops is a global stack. Some commands can "return" values, and in such a case they push a value at the top of the stack. Like:

PROMPT "Tell me your name:"

asks the player for their name, and puts them at the top of the stack (denoted %1). So, assuming that the player answered "John", the stack will look like:

%1 "John"

If we then ask the player about their class:

PROMPT "Tell me your class:"

the class will jump on the top of the stack, resulting in something like this:

%1 "Warrior"
%2 "John"

The thing to remember is that the return values go to the top of the stack, subsequently pushing the existing values "lower".

The values on the stack can be referred to in command parameters. So the command:

DISPLAY "Hello %2, mighty %1!"

will display the text Hello John, mighty Warrior!

The stack in GameLoops can be only pushed to, there is no way to revoke/pop values from it (although they can be retrieved like shown above).