ID:1691309
 
(See the best response by Kaiochao.)
I'm implementing a 'genetics' system, where every living thing is composed of blocks(datums)

How i want to do it, is when the event is called, have the genomes themselves add new variables to the mob.

So rather than in:

mob/whatever
var/skintone


I want to:

datum/genome
whatever.skintone


Keep in mind, skintone is not an already defined variable for the mob, i want to define it from the datum.

How can i do this?
You can't add or remove variables because they exist and are checked at compile-time. At the cost of compile validation, you can use an associative list, which does allow you to add keys (list(key1 = value1, key2 = value2, ...)) on the fly.
data // starting a datum with datum/ is unnecessary
var data[0]

// ...
var data/d = new
d.data["skintone"] = some_value

world << d.data["skintone"]
I THINK i get it? Are you saying i should assign the variable to the datum, and have the mob reference the datum for the values?

The idea is that if you dont have a particular genome, say skintone, The others will be buggy (intentional.) So if you removed the skintone, They wouldnt have a skintone variable. If you removed the 'liver' they wouldnt have liver stuff, etc.
In response to Nullbear
You're asking for a list.
var genomes[0]
genomes += "skintone"
// now genomes contains "skintone"

genomes += "liver"
// now genomes contains "liver"


If you want these parts to be associated to some value, as if it were a variable, you'd do that like so:
genomes["skintone"] = some_value
genomes["liver"] = some_other_value

// now genomes contains a skintone key that has the value some_value
// and a liver key that has the value some_other_value


It's similar to variables in that you can get/set them.
var data[0]
data[key] = value // adds 'key' to 'data' and associates it to 'value'
return data[key] // returns 'value'

// instead of
data
var key = value

var data/data = new
data.key = value
return data.key
Yes, I'm using a list for the individual genomes. They're called "blocks" and have names like human-chromosome-1 etc, and reference the genomes datum to get info on what variables to add, etc. They have a value of one byte per block, which can be either a number between 0 and 255, Or a total of 8 bitflags.

Now im wondering how it should create a new mob, a separate entity, from a list of dna blocks and their values.

I could just have a massive string of code saying:

If /hiuman-Chromosome-1 in list
if bitflag 1
do this
if bitflag 2
do this
if bitflag 3
do this
if bitflag 4
do this
if bitflag 5
do this
if bitflag 6
do this
if bitflag 7
do this
if bitflag 8
do this

If human-Chromosome-2 in list
if bitflag1
do this
if bitflag2
do this
if bitflag 3
do this
if bitflag 4
do this
if bitflag 5
do this
if bitflag 6
do this
if bitflag 7
do this
if bitflag 8
do this


And so on for all of the 7350 possible dna blocks. Is that what you're expecting?

So each DNA block holds 8 'genomes' which can be either on, or off, determined using bitflag values paired with dnablocks.
In response to Nullbear
I'm not sure how this relates to the original question, which was to add variables to an object.
How will the object reference the variables? In the list, correct? So it would just have 7350*8 if statements checking if the variable existed, in order to add a certain body part etc?

What i wanted to know in the beginning, was if i could have the datum add variables to the mob depending on which were active, So instead of checking if they were active, it would be told which were active.

dna = new("hC1" = 243, "hC2" = 21, ...)


And so on for every dna block and its value, rather than:

New()
if hC1 in dna
do this
if hC2 in dna
do this


etc. But forget it.
In response to Nullbear
Best response
When you use a variable:
object.variable
object.variable = value

This is equivalent to this, which exists in DM:
object.vars["variable"]
object.vars["variable"] = value

But if you want to add or remove variables, you use a different list, because you can't do that to the built-in vars list.
object.data["variable"]
object.data["variable"] = value

So, I'm not sure what difference it makes if you use a list instead of actual variables. Do you understand this? What problems are you continuing on with?
None. I was just trying to clarify. Ive decoded on another system regardless though.