I'm a bit tired, so I might not explain well here. Ask questions if you're confused.
1) Allow the creation of new "types". These types would be extensions of basic items and cleverly map to some number of C++ classes. Basically, the modder describes what fields there are, whether they are mutable once the item is created, and whether the field is an int or a float. Also possibly have readonly fields that only exist on the Lua prototype table. By only allowing up to four fields, you only need 5 C++ classes. The main benefits this has over the other two proposals is that it lets the modder better describe what they're doing, giving them express control over naming and types. It's easier to remember 'life' than it is to remember 'meta3' for instance. The main drawback is that it's more complex to implement.
Code: Select all
data:extend({
type= "item-type",
name= "breeder",
field1= {name="fertility", type="float", readonly=true},
field2= {name="lifespan", type="int", readonly=true},
field3= {name="life", type="int", readonly=false},
statics = {"output"="string", quality="int"}
},
{
type ="breeder" -- As per the type defined above
name ="juice-breeder",
-- Omitted: All the usual item properties like icon and flags
output = "breeder-juice"
quality = 1
}
})
-- And then to create a juice-breeder, one of the following
jb = game.createentity(name="juice-breeder", position=somePosition, fields={fertility=0.2, lifespan=5000, life=5000})
jb = game.createentityof("breeder")(name="juice-breeder", position=somePosition, fertility=0.2, lifespan=5000, life=5000)
-- And then to mutate a property
jb.life = jb.life - 1
-- And then to read a static property
print(jb.output) -- "breeder-juice"
Code: Select all
data:extend({
type="fat-item"
name="juice-breeder",
-- Omitted usual item properties as per previous example.
static={"output"="breeder-juice"}, -- actually, being able to define properties like this on all prototypes would be nice.
meta2 = 5000.0, -- default value if not explicitly defined during instantiation.
meta3 = 5000.0, -- default value is 0.0 if not left out, such as meta1 here.
})
-- Creating a juice-breeder
jb = createfatentity(name="juice-breeder", position=somePosition, meta1=0.20)
-- Reading the static properties.
jb.static.output -- "breeder-juice"