Re: Programming Inform


22 May 1995 08:51:24 GMT

Julian Arnold <jools@arnod.demon.co.uk> wrote:
> I can see three ways to store [the current amount of cash the player
> has]:
>
> a) in a global variable
>
> b) by [creating a separate object to manage the player's money and]
> using the property 'number' and giving it the value 500
>
> c) by [creating a separate object to manage the player's money and]
> creating a new property, say 'value', and using it in the Object
> definition
>
> Is one of these possibilities preferable to the others? Will
> large-scale use affect the speed (compiling and run-time)? Is it just
> a matter of preferred source-code style?

This is just a matter of style. There's no particular point in using
objects to store information that could be stored in a global variable
or array unless it would make programming easier, or unless you can take
advantage of the object-orientation. Globals are slightly faster to
look up than object properties, but I would be enormously surprised if
you could see any speed difference (calculating the player's wealth is
unlikely to be an important bottleneck!).

Yet another solution would be to have a bunch of of objects representing
one-dollar bills, five-dollar bills, and so on.

--
Gareth Rees