DEV website instance!Program structureThe game starts with a one-off announcement of the player's arrival at the Opera House. For now, we'll skip the actual arrival message and use the traditional "Hello world!" instead. init say "Hello world!" repeat stop That's a fully functional A-code program, which will print its message and stop. The INIT and REPEAT code sections are mandatory. Either or both can be empty, though this would not make sense in any real game. INIT code sections are used for game initialisation. If there are several, they get executed in the order or their declaration. The REPEAT sections (also executed in the order of their declaration) constitute the main loop of the game. So INIT sections get executed once and then the game repeatedly executes the REPEAT sections in their order, until the stop directive is encountered. The actual initial message for our game is a multi-line one, with some lines being blank. Nevertheless, we could simply substitute it for "Hello world!" in the program so far: init say " The Cloak of Darkness Hurrying through the rain-swept November night, you're glad to see the bright lights of the Opera House. It's surprising that there aren't more people about but, hey, what do you expect in a cheap demo game...? " repeat stop Notice that all text lines are preceded by some blanks – only major directives start at the beginning of a line. Any such leading blanks are ignored and successive non-blank lines are interpreted as a single line to be wrapped at runtime as appropriate. Within text definitions, blank lines can be completely blank (no spaces or tabs preceding end of line). However, I reckon this use of multi-line text is untidy and makes code less readable. So I'll use a named text instead. text YOU.ARRIVE The Cloak of Darkness Hurrying through the rain-swept November night, you're glad to see the bright lights of the Opera House. It's surprising that there aren't more people about but, hey, what do you expect in a cheap demo game...? init say you.arrive repeat stop Note that no double quotes are used in defining named texts. The text is simply terminated by the next declaration (or end of file).
|