The ZED Scripting Language Specification

strawberriesfarctateSoftware and s/w Development

Nov 4, 2013 (3 years and 5 months ago)

64 views

The ZED Scripting Language
Specification
All work Copyright c￿2003 by Limebird Entertainment & the ZED-42 project
Written Mikael Hedberg,d00-mhe@nada.kth.se,
Josef Grahn,d00-jgr@nada.kth.se,
and Niklas Lundström,d00-nlu@nada.kth.se
Version 1.4,2003-03-12
Contents
1 Revision history 1
2 The language 2
2.1 Introduction............................2
2.2 Names...............................2
2.3 Comments.............................2
2.4 Strings...............................2
2.5 Whitespace............................2
2.6 Example..............................2
3 Syntax 5
3.1 Animations............................5
3.2 Objects..............................5
3.3 Conditions.............................6
3.4 Dialogues.............................6
3.5 Statements.............................6
3.5.1 Animate..........................7
3.5.2 Be.............................7
3.5.3 Drop............................7
3.5.4 Get.............................7
3.5.5 Show............................7
3.6 Subroutine calls..........................7
3.7 Conditional constructions....................8
3.8 Keywords.............................8
3.9 Precedence.............................8
4 Grammar 9
i
1 Revision history
Version 1.0:Initial revision.
Version 1.1:Removed player object,added inventories and “has” conditional.
Version 1.2:Moved dialogue name in “show” statements.
Version 1.3:Made dialogue name in “show” statements and object name in “has”
conditionals optional.
Version 1.4:Clearification of when trigger order.
1
2 The language
The ZED scripting language is used to describe the objects in a world and
the possible interactions between them in an adventure-game setting.
2.1 Introduction
A ZED script consists of a sequence of definitions of Animations,Conditions,
Objects and Dialogues.The language is case-insensitive and delimited by
newlines.Each entity of its type runs until the next entity or until the end
of file.
2.2 Names
Names in a ZED script are strings of alphanumeric characters and under-
score characters.Names must be unique among Objects,Conditions and
Dialogues.Also,names of conditions and states must not collide.
2.3 Comments
Comments in a ZED script run to the end of the row and start with the
character ‘#’.
2.4 Strings
Strings in ZED scripts are delimited by quotation marks (").To include
quotation marks in a string,use the escape character\.To write a backslash
character,use a double backslash (\\),and to include a newline in a string,
use\n.
2.5 Whitespace
Any whitespace required will not be checked for length.Space characters,
tab characters and colon characters (:) are considered whitespace.Multiple
consecutive lines containing only whitespace or comments will be treated as
one single newline.
2.6 Example
Consider our hero trapped.There’s a gate barring the way and a hungry
monster guarding the gate.Note that in a real-world game you’d probably
want to have much more animations and a more detailed dialogue in here.
2
#Declare the animations to play.These are then played through
#callbacks to the game
Animation takething
Animation opengate
#A player object to keep track of inventory and general states
Object Hero
states prisoner free
when (finished and prisoner)
be free
#A condition to help us
Condition finished
Gate open
Creature eating
#This dialogue describes the conversations the hero can have
#with the monster
Dialogue MonsterTalk
line l1"Let me pass"
response("i’m hungry")
line l2"Let me pass"
response("munch munch - do what you want")
line l3"Taste good?"
response("yum yum")
line l4"Let me pass!"
response("Me want yummy steak!")
situation s1 l1
situation s2 l2 l3
situation s3 l4
Object Gate
states closed open
on Use Key (closed)
be open
animate opengate
on Use Key
3
response("It’s already open!")
Object Key
on Take
Hero get Key
animate takething
Object Steak
states raw roasted
on Take
Hero get Steak
animate takething
Object Fire
on Use Steak (Steak raw)
Steak be roasted
Object Creature
states hungry eating
on Give Steak (hungry and Steak roasted)
be eating
Hero drop Steak
on Give
response("i only eat tasty food")
on Talk (Hero has Steak)
MonsterTalk show s3
on Talk (hungry)
MonsterTalk show s1
on Talk
MonsterTalk show s2
when hungry becomes eating
response("Yum yum")
4
3 Syntax
The following section shows the syntax used for each kind of entity in a ZED
script.
3.1 Animations
Animations are declarations that give a handle to play animations in response
to script events.The actual playing of animations will be done from inside
the game engine on an animate statement.
Animation <name>
3.2 Objects
An object is a representation of something in the game world (though not
necessarily something which is visible).Each object has a set of states it can
be in and a set of handlers for certain events that may occur.
A when clause is a reaction which triggers on an internal event,such as a
state changing.When clauses will trigger when the condition changes from
being false to being true.Also,any when clauses initially fulfilled when the
script parsing starts will be triggered.When clauses will trigger recursively
in the order from the top to the bottom of the script.That is,they will
trigger from top to bottom unless a new state change occurs,in which case
the triggers for this state change will occur in the same manner before the
original state change triggers are executed.
An on clause is a reaction which triggers on external events,or verbs,
that come as signals from the game system.Several on clauses can match an
incoming event,in which case the first one in the file will be run.All verbs
used with on clauses are required to exist on the game engine side when a
script executes.The object name is used when a specific object is involved
in a binary verb operation.
Each object also has an inventory which can be checked using the “has”
construction.Objects can be given or taken froman Object’s inventory using
the get and drop statements.
Object <name>
states <statename> [<statename> [...]]
[...]
when [<oldstate>] becomes <state> [(<conditions>)]
5
<statement>
[...]
[...]
when (<conditions>)
<statement>
[...]
[...]
on <verb> [<objectname>] [(<conditions>)]
<statement>
[...]
[...]
3.3 Conditions
A condition is a saved set of conditions that can be evaluated at any time
as the conditions for some event to trigger.A condition is fulfilled if all its
conditionals are fulfilled.
Condition <name>
[<conditional>]
[...]
3.4 Dialogues
A dialogue contains all the elements of a dialogue and what happens when
the player selects a certain line to say.It also contains which lines belong
together and in which situations the player can be.
Dialogue <name>
line <linename> <text>
<statement>
[...]
[...]
situation <sitname> <line> [<line> [...]]
[...]
3.5 Statements
The statements that can be used in reaction to different events in the script
code are made up of certain statements described below.
6
3.5.1 Animate
“Plays” a certain animation.
animate <name>
3.5.2 Be
Changes the state of a certain object.If the object is left out,the current
object is assumed.If there is no current object (as in a Dialogue),the object
has to be included.
[<name>] be <state>
3.5.3 Drop
Removes an item from a object’s inventory.
[<name>] drop <item>
3.5.4 Get
Adds an item to a object’s inventory.
[<name>] get <item>
3.5.5 Show
Show a situation of a Dialogue.
[<dialogue>] show <situation>
3.6 Subroutine calls
Subroutine calls can be used to call back into the game system to have some
action performed.For instance,in the example in section 2.6,response was
one such subroutine callback.
<subroutine>(<string> [<string> [...]])
7
3.7 Conditional constructions
A conditional is a boolean construction dependant on one or more conditions
and/or one or more object states.Each of these booleans may be joined
together using the following constructions:
not <boolean>
<boolean> and <boolean>
<boolean> or <boolean>
(<boolean>)
Each boolean above can in turn be made up of other booleans or one of
the following constructions,where object has to be included if there is no
current object:
<conditions>
[<object>] <state dependencies>
[<object>] has <item>
3.8 Keywords
The following words are reserved in ZED scripts:
and,animate,animation,be,becomes,condition,dialogue,
drop,get,has,line,not,object,on,or,show,
situation,states,when.
3.9 Precedence
The precedence of four operators are of value in ZED scripts.The following
order has been defined,where the highest priority comes first.
• NOT,object
• AND
• OR
The object operator binds strongest,which means that the expression
House burning and shaking means that the House is burning and the cur-
rent object is shaking,rather than that the house is both burning and
shaking.If this second meaning is what is wanted,use parenthesis,as in
House (burning and shaking)
8
4 Grammar
The start symbol is SEQUENCE.
SEQUENCE → ENTITY
| ENTITY SEQUENCE
ENTITY → ANIMATION
| CONDITION
| DIALOGUE
| OBJECT
ANIMATION → animation name endl
CONDITION → condition name endl CBODY
CBODY → PREREQUISITE endl CBODY
| PREREQUISITE endl
PREREQUISITE → not PREREQUISITE
| PREREQUISITE and PREREQUISITE
| PREREQUISITE or PREREQUISITE
| lparen PREREQUISITE rparen
| name
| name PREREQUISITE
| name has name
EBODY → STATEMENT endl EBODY
| STATEMENT endl
OBJECT → object name endl OBODY
OBODY → STATES OBODY
| WHEN OBODY
| ON OBODY
| STATES
| WHEN
| ON
STATES → states STATELIST endl
STATELIST → name STATELIST
| name
ON → on name name lparen PREREQUISITE rparen endl EBODY
| on name lparen PREREQUISITE rparen endl EBODY
| on name name endl EBODY
| on name endl EBODY
WHEN → when name becomes name lparen PREREQUISITE rparen endl EBODY
| when becomes name lparen PREREQUISITE rparen endl EBODY
| when name becomes name endl EBODY
| when becomes name endl EBODY
9
| when lparen PREREQUISITE rparen endl EBODY
DIALOGUE → dialogue name endl DBODY
DBODY → LINE DBODY
| SITUATION DBODY
| LINE
| SITUATION
LINE → line name string endl EBODY
SITUATION → situation name LINELIST endl
LINELIST → name LINELIST
| name
STATEMENT → ANIMATE
| BE
| DROP
| GET
| SHOW
| CALL
ANIMATE → animate name
BE → name be name
| be name
DROP → name drop name
| drop name
GET → name get name
| get name
SHOW → name show name
| show name
CALL → name lparen PARAMS rparen
PARAMS → string PARAMS
| string
10