Академический Документы
Профессиональный Документы
Культура Документы
Preface 1
Document Organization 1
Conventions 2
Getting Help 2
Basic Information 3
What is a script? 3
Character scripts 3
Object scripts 4
World script. 5
Control script 5
Magic Spells 5
Keywords 7
Keywords Table 8
Comments 8
Numbers 9
Tokens 9
Variables 10
String Variables 10
Types of Scripts 15
Introduction Script 15
Character Script 16
Object Script 17
World Script 18
Control Script 18
Resurrection Script 18
Writing Scripts 19
Script Files 19
Function Table 21
Statements 22
Conditional Statements 22
Drop 25
Output Statements 25
Display 26
Input Statements 26
Select 26
Going Places 26
Animation 27
Entering Doors 27
Teleportation 27
Advanced Topics 27
Entry Points 27
Shareware Opportunities 33
D C - G A M E S
Version 4.0
August 1995
Plano TX 75025
(214) 491-1579
Introduction
Preface
The scripts are created using a standard text editor, and can be
as simple or complex as you need them to be. While you can
write a complete game without writing a single line of script, a
small effort on your part to learn how to write script will
result in significantly better games, since you can fine-tune
your creation to work exactly the way you want it to work.
Document Organization
UPPER-CASE-WORDS
italic-words
are used when a new concept is being introduced, and the world
in italics is the name of that concept. They are also used to
indicate that you should be replace the word with an appropriate
name or value.
bold-words
text1 | text2
items separated by a vertical bar (|) mean you get to choose one
of them.
[text1 ]
{ text1 | text2 }
...
Getting Help
You need to read this guide if you are already familiar with the
DCGAMES system and are ready to extend or modify the system to
suit a particular game's requierments.
What is a script?
The script file contains the instructions that tell the game
driver (DCPLAY program) how to handle most aspects of the game.
The system includes a large number of predefined scripts to
handle objects, characters, worlds, etc. You can modify these
scripts to meet your game's individual requirements, and you can
write whole new scripts to extend the number of options you have.
Control scripts
The CONTROL script is called every time you click with the mouse
or press a key on the keyboard. This script decides what action
to take based on your input. Thus, while the default control
script interprets the letter A to mean 'attack' and a click in
the view area with the left mouse button to mean 'look-at', you
can modify the complete interface to do whatever you want.
The control script is also called every 'minute' of game play.
Using the world builder you can specify how time flows in your
game (# of moves per minute, # of minutes per hours, # of hours
per day, # of days per month, # of months per year, current
date, etc.). The game driver then invokes the control script to
keep track of time and allow it to take time dependent actions.
When the game first starts, the INITGAME script will be invoked.
This script is used to present the game's story. You can use
voice, music, graphics, text, animation, etc.
Within this script you also have the chance to create and
customize the player's character or even the whole party. The
default character stored in record 0 of the statistics file
(PLAYERS.DTA) will be used if you don't create one.
Remember that you can set the rules and do whatever you want.
Some games I've seen will reduce an individual's experience as a
penalty for resurection but leave them where they were. Others
will teleport the party to a different location for resurection.
Character scripts.
Object scripts.
These two scripts handle the standard behaviour for all of the
object types defined in DCCTOKEN.DAT. You can add new types to
the list and modify these scripts to handle actions on the new
object types.
You can alter the behavior of an object in several ways. You may
modify the OBJECT.SCR to alter the way existing objects types
work, or define new object types; You can also create a brand
new script file to control the behavior of a specific object.
World scripts.
The world script handles entry and exit from each world, but
other scripts are also involved. For example, the CONTROL
script will generate random monsters only in OUTDOORS, DUNGEON
and HAUNTED worlds. It also handles walking of the 'edge' of the
world (if outdoors you wrap around to the other edge of the
world, but in cities and towns you 'leave' the world).
Magic Spells
For more information on magic, see the Player's Guide and the
World Builder User's Guide.
Basic Script Elements
This section introduces the basic elements that form the script
language. Just like in English you use words to build sentences,
and those words are classified into verbs, adjectives, etc, so
does the script language use a basic set of elements to build
it's sentences.
Keywords
For example:
write("Go Away");
endif;
For example:
! This is a comment
Numbers
Tokens
Variables
String Variables
index* For players, the order in the party. For npcs their
location in the list of npcs.
player.ring The ring being worn by the current player (if any).
npc.shield The shield being used by the current npc (if any).
npc.ring The ring being worn by the current npc (if any).
npc.amulet The amulet being worn by the current npc (if any).
npc.staff The staff being used by the current npc (if any).
npc.bp The last selected backpack item for the current npc.
The backpack can hold up to 16 items, but only one of them is
selected at a time.
Attribute Description
door the door through which you entered the current world.
edgedoor The door through which the player exits the current
world by walking 'of-the-edge' of the world, or casting the
standard 'exit' spell.
This section talks about the different TYPES of scripts you may
want to write, and tries to point out WHY you would want to
write that kind of script, instead of HOW. The actual script
language is presented in the section Script Language Programming
Guide later in this manual.
Introduction Script
You can also modify the group's starting position by seting the
X and Y attributes of the group variable, or by using the
teleport or enter commands.
! FILE : initgame.scr
edit_player( 1,
30, ! points to distribute
Note that the READTEXT command has some voice, music and
graphics capabilities also. The 'intro.txt' file does not
necessarily display a single page of text.
Character Script
You should print out the character scripts and compare each of
them with the description of the character type as given in the
User's Guide. You will then understand how the given script
implements the behavior.
There are three ways of working with character scripts. You can
modify the default scripts to alter the behavior of existing
character types, you can create a brand new character type, with
it's own script, or you can create a unique script for a unique
character.
Object Script
Every time you create a new object type or even a new class
within an object type, you will need to modify the OBJECT and
CURRITEM scripts to handle the new object. For example, mirrors
currently don't do anything. If you wanted to have a mirror
that shows you an area around you, you could create mirror
classes. Class 0 would be a normal mirror, while class 1 would
invoke a 'view' spell. You can then modify the two scripts to
check the class attribute for mirrors and behave accordingly.
Note: Since version 4.0 allows one script to call another, this
description is not entirely correct. The CONTROL script calls
the OBJECT or CURRITEM scripts as needed, and these scripts may
call others, like the CASTING script or the DESCOBJ script.
When the character wears the ring, your script might display the
image of a genie, and ask the player what spell is desired. The
script would then perform the appropriate spell.
World scripts are executed whenever you ENTER or EXIT the world.
The default world script, WORLDDEF.SCR, is invoked if your
world does not have it's own script. The world type and other
attributes configured using DCWORLD allow the WORLDDEF script to
handle most normal situations.
Control Script
Every time you press a key or click with the mouse to handle the
interaction between the player and the game system.
Note: Version 3.x had entry points in the control script for
handling a player leaving the party, winning a fight (for
experience and random treasure), etc. These entrypoints are no
longer needed because version 4.0 is more fully under script
control, so these events happen in their appropriate places
without special "hooks".
Resurrection Script
Writing Scripts
Script Files
Once the script has been saved, you will use the script compiler
to translate the script from human readable form (text) into a
compact code that the game driver understands. The translated
code is written into a file with the same name as the original
file, but with extension of .SCO (for SCript Object).
For example:
Directory of C:\DCGGAME
Labels = 25
Compilation successful
Directory of C:\DCGGAME
Expressions are used in many places, but the most common use of
expressions is on the right side of an assignment statement.
The second most common use for expressions is as part of a flow
control statement, such as if or on, which are examined a bit
later.
Function Table
Function Description
The numeric range (0-N) means that a value in the given range
must be provided when referring to this variable
Examples:
player.level = player.level + 1;
! same as "inc(player.level);"
player.name = "Henry";
Statements
Just like the English language, the script language uses words
and symbols to build sentences or statements which tell the game
driver what to do. A statement is a complete sequence of words
and symbols that tell the game driver how to perform a single
given action.
Conditional Statements
else
endif;
L25 = npc.weapon.damage;
endif;
if player.hp = 0 then
writeln( player.name, " is dead!" );
else
endif;
:AGAIN
if L3 = 0 then
elsif L3 = 1 then
elsif L3 = 2 then
else
endif;
goto AGAIN;
:XSELL
goto AGAIN;
:XBUY
goto AGAIN;
:XTALK
goto AGAIN;
:DOIT
endif;
inc( L6 ); ! Same as L6 = L6 + 1;
The above code uses the goto statement to create a loop that
examines the 16 backpack locations for an object and then copies
the objects (if they exist) to the npc.
L6 = 0;
while L6 < 16 do
setbp( player.bp, L6 );
if player.bp.count then
endif;
inc( L6 );
endwhile;
The for statement simplifies the loop even more by allowing you
to specify both the initial value, the final value and the
amount by which the control variable (L6) is to be incremented
(or decremented). Thus, the loop becomes:
for L6 = 0 to 15 do
setbp( player.bp, L6 );
if player.bp.count then
endif;
endfor;
foreach player.bp do
endfor;
The copy statement works the same way, but does not delete the
object from the source, thus making a copy instead of moving the
object.
In both cases, you can specify how many objects you want to
move. The command will move as many as the destination can
possibly hold. If you specify that you want to move or copy
more objects than are available in the source, additional
objects are created.
Drop
Output Statements
When you want to display a value, you have several ways of doing
it. The most simple one is the write or writeln statement.
With this statement you can display all attributes and variables
as well as text.
else
L7 = Hour - HoursInADay / 2;
endif;
Display
Input Statements
Frequently, when you display something you are asking the player
for directions; During a conversation, you ask the player what
they want to talk about; A merchant might display a list of
items and ask which you want to buy.
The getnum function displays a string and asks the user to enter
a value in a given range. Only values in the range are allowed.
If the user presses Esc instead of typing a number, the
function returns -1.
Select
There are several ways in which characters and objects may move
under script control.
Animation
Entering Doors
Teleportation
Advanced Topics
Entry Points
From within a script, you may execute a DOS program by using the
system command. This command works exactly like the writeln
command, except that instead of sending a line of text to the
text window, the text is formed into an MS-DOS command and
executed. When the command ends execution, the MS-DOS error
level is stored in the failure variable. A value of 0 usually
indicates success.
[CHARACTER TYPES]
LAWYER 12
In the above segment, the new character type LAWYER has number
12 assigned to it (the next available number). You may now
write a script file called LAWYER.SCR to handle the default
behaviour of lawyers.
[CHARACTER CLASSES]
THIEF 6
In the above segment, the new character class THIEF has a number
6 (next available one).
You may also want to modify the OBJECT and CASTING scripts to
give a thief certain advantages when dealing with traps, and to
enable or restrict the kinds of weapons, magic, etc, that the
character can handle.
New Object Types
The object types Food, Weapon, Armor, Shield, Amulet, Ring and
Staff have special treatment because they can be worn by the
characters. The Vehicle object type also has special handling
because it can be used for transportation. Other than these
special handling, you can modify the OBJECT script file as much
as you want.
If your new object is going to have the same set of class items
that already exists for another type, just add the name to the
list, for example:
PLUS_AC 9 ! Increase AC
PLUS_HP 10 ! Increase HP
PLUS_IQ 11 ! Increase IQ
Here, we have added the new object type WIDGET to the set of
objects that have personal magic.
on object.type goto
:USE_AMULET
:USE_RING
:USE_ARMOR
:USE_WEAPON
:USE_SHIELD
:USE_STAFF
STOP;
:USE_WIDGET
writeln( "If you want to use it, you must first 'get' it.."
);
STOP;
.
If your new object is different from all other objects, you can
create a brand new section for it's classes in the DCCTOKEN.DAT
file:
At this point, you may create graphics blocks with type widget
and class round, square or oval. You may also write script code
like this:
stop;
endif;
....
STOP;
....
STOP;
....
STOP;
New Object Modifiers
When you create a new object type and/or class, you may want to
create new names for those fields that you might use to
differentiate between them For example:
[OBJECT MODIFIERS]
! 0 Is not used
! 3 Is not used
! 4 Is not used
! 4 Is not used
Note that if you want to use a token that already has a value
assigned, like range in the example, which has a value 1
assigned for weapons, you MUST use the same value for the token.
Tokens are replaced by their numeric value during compilation,
so the following two lines are equivalent:
if object.hands = 7 then ...
Both lines are comparing the m0 modifier of the object with the
value 7. The type of the object is not checked to see that the
token you are using belongs to the object's type.
While most users will use the script language to make small
changes to the game system, with a few customized scripts to
handle special characters or objects, the true power of scripts
lies in the ability to completely change the way everything
works. Here are a few example of some more complex projects
that you may want to attempt once you are comfortable writing
scripts:
You can also change the scripts to handle a lot more spells (up
to 255 of each type), or add a level requirement for each spell.
The system command allows you to run DOS programs from within a
script. The following DOS programs could be called from a
script to extend the functionality of the system. Writing these
extensions requires knowledge about internal structures of the
game files, which I will be glad to provide on a case by case
basis.
Save/Restore/Restart
Character Editor
Arcade/Casino extensions
Primary Keywords
continue
copy
dec
display
drop
endgame
enter
fight
find
for
foreach
frame
getaction1
getnum
getstr
goto
gosub
if
inc
join
leave
loadhint
loadtext
locate
move
on
paint
pause
readtext
restart
restore
return
runscript1
save
savepcx1
select
setbody
setbp
stats
stop
teleport
vanish
viewfli1
viewpcx
voice
vplay
wait
while
write
writeln
Secondary Keywords
if
expression
for
foreach
- do, endfor
while
- endwhile
select, display
- matching
paint
- screen, window
Function Keywords
abs
action
adjustments
Day
DaysInAMonth
DefCaveBlk
DefLandBlk
DefPack
DefSpookBlk
DefStat
DefWaterBlk
fighting
failure
Hour
HoursInADay
keypress1
max
min
Minute
MinutesInAnHour
Month
MonthsInAYear
MovesPerMinute
pointx1
pointy1
random
success
SunSet
SunRise
version
Year