Previous Section : General Concepts previous section next section Next Section : Scripting the Universe...

"I Object!"

Semantic Needs

Herein, I show some language constructions that try to grasp the ontological complexity presented in the previous section. This will reveal the backbone for the design language. The main goal is to achieve expressive power.

Contents
Classes
Data Types
Operators and Methods
Events
States

 

Classes

There must be an initial class taxonomy where everything should descend. This is a possible scheme:

Object
Physical-Object
Thing
Primitive
Agent
Player
Daemons
Bot
Composed
Stuff
Solid
Liquid
Gas
Magical
Abstract-Object
World
Sector
Event
Process
State
Message
Place (set of events)
Interval (set of events)
Measure
Objective
Click
Unit
Subjective
Relation
Function
Reified-Class

note Some of these concepts may not be treated as classes (like measures and functions) due to implementation reasons.

 

Data Types

A very important subject in script languages (SL) is data types! SL are very high level control languages for program configuration, and they need powerful data types to handle complex information.

The standard primitive types usually are: boolean (e.g., true, false), integer (e.g., 12, 0, -435), real (e.g., -1.4, 5.0e-1) and string (e.g., "hello, virtual world"). We will include space measure unit (e.g., 123u),  time measure click (e.g., 123c), mass measure gram (e.g., 64500g), energy measure joule (e.g., 25j) and tuple (e.g., <1.3,0.0>, <1.2,-1.0,23.1>). Object types are also available in order to define new class instances or reference existing ones.

Some languages provide associative arrays (or tables) as a predefined type (Perl, Tcl, Lua). This type is very powerful, it is possible to define records, arrays, lists, sets, bags, hash-tables, even objects (if functions are seen as first class values, i.e., can be assigned to variables). Basically, an associative array is a table that can be indexed not only by integers, but by other data types, such as strings, reals, whatever.

A common instruction, used in tuples, lists or tables, is the iterator operator:

for x in set do block - iterates through all elements of set.

 

Operators and Methods

in addition to the usual operators for primitive types, there are the following ones:

Object dynamics (Object class methods)

spawn( class, configuration ) returns a new object of class, based on the given configuration.
destroy( ) destroys object (in principle, only the Universe and its father can do it)
id( ) returns the object's unique ID.
birth( ) returns the object's creation time.
child( ) returns all objects spawned by object.
father( ) returns who spawned this object, or nil if spawned by the Universe.

Tags (Object class methods)

note Every object can have zero, one or more tags attached. These tags provide a way to give general information about objects relations and descriptions.

tag-insert( string-Tag ) insert string-Tag into object.
tag-remove( string-Tag ) remove string-Tag from object.
tag-collection( ) returns all tags from object.
tag-similar( list-Objects ) returns all objects from list-Objects with same tags as object.
tag-related( list-Objects ) returns all objects from list-Objects with at least one equal tag as object.
tag-listag( list-Objects ) returns all tags that object has, that are related to at least one other object from list-Objects.
tag-has( string-Tag ) returns true if object has string-Tag.

Messages (Object class methods)

msg-send( message, object ) sends message to object.
msg-send( message, tag ) sends message to all objects with tag.
msg-broadcast( message ) sends message to all objects.
msg-receive( message ) receives next message. Linked to event evt-message by default.
msg-filter( object ) refuses messages from object.
msg-filter( tag ) refuses messages from objects with tag.
msg-encrypt( message, key ) returns the encrypted message using key.
msg-decrypt( message, key ) returns the decrypted message using key.

new stuff!

msg-translate( message, language ) returns the message translation on language.
msg-cover( message, energy ) use energy to cover message before send.
msg-intercept( energy ) returns a list of tuples (sender, message, receiver) intercepted with cover energy < energy. The value of energy decreases as higher is the distance between the sender and the intercepting object.
msg-jam(   energy ) jams all messages with cover energy < energy. Each message is jammed within a specific probability (which increases as higher is the difference between cover energy and jamming energy). The value of energy decreases as higher is the distance between the sender and the jamming object.

Sector parameters (Sector class methods)

sct-name( string-Name ) set sector name.
sct-in( ) returns supersector.
sct-list( ) returns all subsectors.
sct-frontier( tuple-Points, height ) define sector frontier given by tuple-Points and height. So, sectors are, in this case, polygonal cylinders.
sct-set( string-Parameter, value ) set string-Parameter to value.
sct-get( string-Parameter ) returns string-Parameter value.
sct-param() returns all parameters with associate values.
sct-access( allowed? ) if allowed? is true, any object can cross the sector frontier, false, otherwise.
sct-access( tag ) only objects with tag can cross sector frontier (if allowed? is true).
sct-enter( method ) execute method to each object entering sector.
sct-exit( method ) execute method to each object exiting sector.

Physical Objects (Physical-Object class methods)

psc-mass( ) returns the object's mass in grams.
psc-energy( ) returns the object's energy in joules.
psc-center( ) returns a tuple informing the actual center of gravity of object.
psc-vector( ) returns a tuple informing the actual velocity and acceleration of object.
psc-sector( ) returns the object actual sector (returns "world" if it is not in any sector).
psc-inside( sector ) returns true if object is inside sector, false otherwise.

Inventory (Thing class methods)

inventory( ) returns all objects in inventory.
inv-insert( object, int-Uses ) inserts object into inventory. If int-Uses > 0, then the object can be used just int-Uses times.
inv-remove( object ) removes object from inventory.
inv-reset( ) resets inventory.
inv-number( class, recursive? ) returns the number of instances of class in inventory. If recursive is true, it also counts the sub-classes instances.
inv-use( object ) use object of inventory. A used object may have a maximum number of uses, before it is removed (see inv-insert).

Composition (Composed class methods)

cps-define( list-Structure, reversible? ) informs what is the list-structure template for composed class, and if it reversible or not.
cps-insert( object ) inserts object into structure template.
cps-remove( object ) removes object from structure template.
cps-reset( ) resets structure template.
cps-structure - returns the structure template of object class.

note These first methods are static (per-class members), i.e., each object belonging to this specific class, share the same structure template.

cps-compose( list-Structure ) returns a new composed object made out of list-Structure. It destroys all objects belonging to list-Structure.
cps-decompose( ) creates a set of objects defined in structure template and destroys composed object. This is only possible if object is reversible.
cps-blend( class ) returns a new primitive object of class, based on composed-object. (e.g., it is possible to construct a bot made of several parts, and then activate it, blending as an agent). The composed object is destroyed.

Stuff (Stuff class methods)

stf-define( quantity, type, args, ... ) defines the new stuff object having quantity of some type (user or pre-defined) and some more intrinsic/extrinsic arguments.
stf-divide( quantity, to-Object, connected? ) creates to-Object of the same class, with quantity (subtracting that quantity from initial object), and stating that this new object is(is not) connected. If quantity is greater or equal than initial object, the method does nothing.
stf-blend( with-Object ) blends object with with-Object. Both their quantities are added and with-Object is destroyed.
is-same( object ) returns true if both objects are of the same initial stuff (i.e., in the past, they belonged to the same stuff object).
is-connected( object ) returns true if both objects are connected.

note Connections may be defined by the tag system, using a special prefix "stf-" for stuff tags

Daemons (Daemon class methods)

dmn-set( timer-Name, click-Interval, method ) sets timer-Name of specific daemon, activating method on every click-Interval (if zero, then it never triggers except for a dmn-trigger call).
dmn-start( timer-Name ) starts timer-Name.
dmn-stop( timer-Name ) stops timer-Name.
dmn-left( timer-Name ) returns the number of clicks to next activation of timer-Name.
dmn-reset( timer-Name ) resets timer-Name.
dmn-trigger( timer-Name ) triggers timer-Name even if there is some time left.
dmn-trigger( radius, class, timer-Name ) triggers timer-Name if an object is an instance of class and approach the deamon at a distance less then radius.
dmn-link( object ) links daemon to specified object.
dmn-split( object ) splits daemon from specified object.
dmn-list( ) returns all objects linked to daemon.

Space-Time (general methods)

radius( tuple-Location, unit-Radius )  returns all objects at distance <= unit-Radius from tuple-Location.
inside( tuple-Top-Left, tuple-Bottom-Right ) returns all objects inside the area (volume, if 3D) defined by tuple-Top-Left and tuple-Bottom-Right.
inside( string-Sector ) returns all objects inside string-Sector.
trace( tuple-Start, tuple-End, unit-Distance ) returns all objects that intersect the line defined by tuple-Start to tuple-End at a distance <= click-Distance of that line.
with-age( click-Min-Age, click-Max-Age ) returns all objects with age between click-Min-Age and click-Max-Age.
visible(tuple-Location [, tuple-Direction] ) returns all objects visible at tuple-Location with an optional sight defined by tuple-Direction.

Tuples (general methods)

tpl-distance( tuple-1, tuple-2 ) returns the distance in clicks between both tuples.
tpl-size( tuple ) returns the Euclidean size of tuple, the square root of the sum of the components squared.
tpl-norm( tuple ) returns a tuple with size 1, with the same direction as tuple.
tpl-random( integer-Dim ) returns a random tuple with integer-Dim dimensions.
tpl-mirror(tuple, tuple-Base ) returns the mirror of tuple, based on tuple-Base.

Miscellany (general methods)

type( variable ) returns the variable type
class( object ) returns the object's class.
super( class ) returns the super-class of class.
includes(class-1, class-2) returns true iff class-2 is a subclass of class-1.
belongs(object, class) returns true iff object is an instance of class or of one of its subclasses.
is-a(object, class) returns true iff object is an instance of class or one of its superclasses.
reify( class, destroy? ) returns a new object of class reified-Class having one measure: the number of existing objects of that class. Those objects are destroyed if boolean argument destroy? is true.
tag( string-Tag, list-Objects ) returns all objects from list-Objects tagged with string-Tag.
intersect( list-Object-1, list-Object-2 ) returns the intersection of lists. Two objects are compared by their unique ID.
union( list-Object-1, list-Object-2 ) returns the union of lists.
log( string ) writes string at log file
place( tuple-Location, unit-Radius ) save to log file all events occuring in the place defined by tuple-Location and unit-Radius.
interval( click-Start, click-Stop ) save to log file all events occuring in the interval defined by click-Start and click-Stop.

 

Events

An event is sent to the object event queue, with eventual strings holding some parameters. Each event can be handled by a specific method receiving these parameters. This can be stated by a special procedure in the class definition (of course, this will depend on the chosen implementation language):

insertEvent( event-name, method, arguments ) - defines called method for certain event.

These are possible events:

evt-spawned - the object was just created.
evt-destroyed - the object is about to be destroyed.
evt-message - receive message event, it has a string "sender", a string "content", and a string "receiver" or "tag".
evt-used - the object was used by some other object.
evt-touched - the object was touched by some other object.
evt-damaged - the object was damaged by some weapon or explosion.
evt-daemon - started some daemon's timer, it specifies the daemon and its timer.
evt-seen - the object was seen by an agent for the first time, it specifies which agent it is.
evt-entered - the object just entered a specific sector, it specifies which sector it is.
evt-exited - the object just exited a specific sector, it specifies which sector it is.
evt-state - the object changed state, it has two strings "old-state" and "new-state".

Arbitrary user events can be created (using "evt-" prefix in event names):

new-Event( string-Name, parameters... ) creates and returns a user defined event with string-Name and structured by the following arguments.

Also, an event can be triggered explicitly:

object-name.forceEvent()

 

States

An object can be defined by a set of states (like in state automata programming). A method can be redefined for each state, giving different behaviors depending on the actual object state. To jump between states, the jump instruction can be used:

jump('state') - jumps to 'state'.

State programming is a very rare feature in programming languages, to my knowledge only UnrealScript deals directly with it. If using a language that does not use states, it should be simulated.

There are some complex issues relative to mixing inheritance and object states. Check the UnrealScript documentation to find more information.

 

Previous Section : General Concepts previous section to top next section Next Section : Scripting the Universe...

Last modified: 27/09/04 by Joćo Pedro Neto send me an email zipped contents wanna search the matrix?