here 's (one of) the extension I’m working on:
[spoiler][code]
Easier Dynamic Objects by Phonatacid begins here.
Include Dynamic Objects by Jesse McGrew.
Use thriftiness translates as (- Constant EDO_THRIFTINESS; -).
Part 1 - New objects
Chapter 1 - Pools for alive and dead objects
An abstract pool is a kind of container.
The object_alive_pool is an abstract pool.
The object_dead_pool is an abstract pool.
Chapter 2 - The ‘New K’ phrase
[will trigger a series errors at compilation time if it is applied to a non-object value]
To decide what K is a new (name of kind of value K):
let D be the default value of K;
if the thriftiness option is active:
if there is a K contained by the object_dead_pool:
let RV be a random K contained by the object_dead_pool;
follow the Object Resuscitation rulebook for RV;
[copy the properties of the default value of K to RV]
decide on RV;
else:
let RV be a new object cloned from D;
move RV to the object_alive_pool;
decide on RV;
else:
decide on a new object cloned from D;
Section 1 - The Object Resuscitation rulebook
[this rulebook can be used for resetting the object’s properties to their default values.]
The Object Resuscitation rules is a thing based rulebook.
First Object Resuscitation for a thing (called O)
(this is the default resuscitation rule):
move O to the object_alive_pool;
Chapter 3 - Destroying Objects
To destroy (O - object):
move V to the object_dead_pool;
Part 2 - Properties management
Chapter 1- Creating objects along with their properties
[For instance,
let x be a new man with “george” as printed name and 28kg as weight;
Unfortunately it won’t compile but this willl
let x be (a new man with "george as printed name) and 28kg as weight;]
To decide what K is (O - value of kind K) with/and (V - L) as (P - value of kind L valued property):
change the P property of O to V;
decide on O;
To change the (P - word value of kind K valued property) property of (O - object) to (V - K):
(- WriteGProperty(OBJECT_TY, {O}, {P}, {V}); -).
To change the (P - pointer value of kind K valued property) property of (O - object) to (V - K):
(- BlkValueCopy(GProperty(OBJECT_TY, {O}, {P}), {V}); -).
To change (P - indexed text valued property) property of (O - object) to (V - text):
(- BlkValueCast(GProperty(OBJECT_TY, {O}, {P}), INDEXED_TEXT_TY, TEXT_TY, {V}); -).
Chapter 2 - Copying properties from object to object
[To copy the properties of (SRC - value of kind K) in/into/to (DST - K):
(- EDO_CopyProperties({SRC}, {DST}); -).
Include(-
[ EDO_CopyProperties src dst;
];-).
]
Easier Dynamic Objects ends here.
[/code][/spoiler]
How it works :
Based on a suggestion I received from Jesse, this extension now allows objects to be (pseudo) destroyed :
-when an object is destroyed, it is pooled to an off-stage container
-when an object of kind K is created, the system looks for a (unused) K in the aforementioned container instead of blindly creating a new object.
[u]A few problems[/u]
-I haven’t been able to create a routine that copies the properties from one K to another (so that the properties of a K are reinitialized to the properties of the default value when resuscitating an object. As a workaround, you can write an Object Resuscitation rule for K;
-You can now set several properties with one line only:
let x be a new man with “George” as printed name;
but
let x be a new man;
let x be x with “George” as printed name;
is also possible.
you can change multiple properties at once:
let x be a new man with “George” as printed name and 92kg as weight;
If you want to change/set more than 2 properties, you’ll have to help the compiler with a few parenthesis
let x be (a new man with "George as printed name and 92kg as weight) and 5 as strength;
I thought I could overcome this problem by using line breaks, but unfortunately, line break aren’t considered as parenthesis by the compiler. Maybe that would make for a good suggestion ?
edit: oh and sorry for the previous jazz. you were right about the GProperty routines.