Hi!

Ok, I said, I would stop discussing this, but it is very dear to me 
and appearantly not everybody actually understood what I wanted 
because I was too abstract, so I'll give an extensive example to 
lighten things up. As there seem to be many game programmers on this 
list: Take a game where you don't know how many players participate. 
We need to store the following properties about players: Turn order, 
name, color, and score. We store this data into a global variable 
"player_data" like this (the line number is the turn order):

Scott,Blue,26353
Andrew,Red,1955
Karl,Indigo,53
Kevin,Green,953

This is a very elegant way to store data, because it is easily 
expanded to include more players or columns, and it is easy to access 
that data:

   put line x of player_data into currentPlayer
   put item 1 of currentPlayer into currentName
   put item 2 of currentPlayer into currentColor
   put item 3 of currentPlayer into currentScore


Problem 1:
You'll find yourself getting a bit sluggish:
   set the backCoror of btn ("player"&x) to item 2 of line x of player_data

Sooner or later, after you've added about 20 or more columns, you'll 
start to get into trouble because you can't remember what item the 
color is in or what data is in column 17 (especially if you did not 
touch the project for a while).

Solution 1:
You create a function that turns a fixed "column name" into the column number:
   put item playerColumn("color") of line x of player_data into ...
(Thank goodness this is only a hypothetical program, so I don't have 
to change the whole program now ... ;-)


Problem 2:
The users can enter their names, and someone may enter "Raney, 
Scott". That breaks the item numbering.

Solution 2:
We replace all commas by numToChar(1) in the name before we store the 
name (and any returns by space) and vice versa before displaying the 
data using two functions hideCommas and showCommas.
   put showCommas(item playerColumn("name") of line x of player_data) into ...


Problem 3:
Now players can become part of several groups, so we store the player 
line numbers into items of a global variable group_members (where 
each line has a corresponding line in the global variable group_data).
As the game matures it happens that the need arrises to change the 
turn order dynamically. This breaks the group membership mechanism!

Solution 3:
We add two columns to the player_data variable: The explicit turn 
number and the player id. We could have used the line number as ids, 
but if the game is running distributed in a network, in order to have 
unique ids, players would have to get their ids from one single 
machine, which may not be desirable. If every machine can generate 
their own ids, they can attatch the machine id and there you are.
Now we need two index functions that take the id or the turn number 
and return the line number for the player_data variable. That makes 
it:

   put showCommas(item playerColumn("name")\
     of line playerID_index(x) of player_data) into ...

Now compare that to what you can say with custom classes available:

   put the name of player id x into ...



*excited voice on* This alone is an *even more emphasis* Amazing 
Discovery, but look what you get in addition FOR FREE *excited voice 
off*:

1. You don't have to remember if a column has to be "unhidden". Maybe 
there are color names that contain commas!

2. Some properties may be dynamically resolved. Maybe some property 
"level" which is calculated from the score a player has and certain 
groups he or she is in. You can even turn a static property dynamic 
and change nothing but the class itself. Say you want to add the role 
title to the name that is generally displayed, just change the 
property into a getProp handler and all is done!

3. If there is inheritance, you can have polymorphism. What that 
means is that you can have Orcs, Unicorns, and Butterflies that all 
share a common superclass Creature, but additionally have individual 
properties like "hornLength" or "wingPattern". There is a property 
"weight" defined in the class, so all creatures share it, but for 
orcs the weight of what they carry must be added. If you have three 
creatures on a chart, you'll have to sum up thir weights to find the 
load of the chart. Without caring about what kind of creatures are in 
the chart (you have an array of long ids in a property of the chart) 
you can add their weights and the Orc "getProp" handler will be 
called.

And there are many many more...

Of cause you can encapsulate most of the behaviour by using 
functions, but you can not send function calls to a different stack, 
you'll have to program two handlers for each and every single 
property, and the calling code looks not as nice and natural as it 
does with properties of custom classes.

Of cause you can use custom propoperties of controls to achive some 
of this functionality, but depending on the application there may be 
no "physical" control representing the object, so you can create 
invisible objects or even a stack that contains them, so you can 
access it like this:

   put the color of btn id x of stack "player_objects"

But that is not as elegant as custom class names are and inheritance 
is more difficult to include seamlessly.

There are millions of things that still can be said and I am willing 
to discuss any of them, but this post is too long already.



Regards
   R�diger


P.S.: Again and again people ask "what happens when the stack that 
contains this or that is lost in some way"? Well, this is a bug... 
the engine should throw an error, disable the objects, it could even 
crash... this is an issue of bug reporting, not one of fault 
tollerance. If a button is missing, thats a bug; if a picture is 
missing, thats a bug; if a stack is missing, thats a bug. I'll have 
to take care this does not happen, so what?
--------------------------------------------------------------------
| Ruediger zu Dohna   GINIT GmbH   0721-96681-63    [EMAIL PROTECTED] |
| PGP-Fingerprint: F1 BF 9D 95 57 26 48 42 FE F8 E8 02 41 1A EE 3E |
--------------------------------------------------------------------

Reply via email to