I’m trying to create object “templates” that I can reuse throughout my story. I have character objects and item objects, each with their own unique template of default properties. And in many cases, my templates have other objects/templates as properties themselves.
So, trimming down to a very simple example (my actual objects have many more properties)… If I have deputies and outlaws, each has their own template. Each character also has a weapon, another object with its own properties. Like so:
<<set $sixshooter = {
rounds: 6,
damage: 10
}>>
<<set $cowboy = {
name: "",
weapon: clone($sixshooter)
}>>
<<set $outlaw = {
name: "",
weapon: clone($sixshooter)
}>>
<<set $outlaw1 = clone($outlaw)>>
<<set $outlaw1.name = "Butch Cassidy">>
So far, this works as intended. I can create characters and everyone automatically gets a six shooter. But what if I want the outlaws to have an advantage, and every outlaw’s gun does 12 damage instead of 10?
I’d like to have code like shown below, which creates outlaws with six shooters (and each gun with 6 bullets), but then changing the damage to 12. (None of this below works):
<<set $outlaw = {
name: "",
weapon: clone($sixshooter)
/* Then change the damage, using: */
weapon.damage: 12,
/* OR */
this.weapon.damage: 12,
/* OR */
weapon: {
damage: 12
} /* while still preserving "rounds" */
}>>
Since none of this works, I’m having to awkwardly add the code I want after the object is created.
<set $outlaw.weapon.damage = 12>>
Is there any way to keep this entirely within the object declaration?
Thanks!