HTML How to setup a breeding system for a Twine management sim?

PsyTurtle

Member
Jan 16, 2022
104
70
I'm working on a kinda management sim. I've been considering using Twine and Sugarcube. It's gonna be very text based and relatively bare bones for now, but I want to include a breeding system. Is there a Twine script or something anywhere for an easy breeding/genetics system? Any resources about how to set up something like that in Twine would also be appreciated.

I remember how to set this kinda thing up in RPG Maker VX Ace. But if I use RPGM, I'll get distracted and start trying to draw the player character and make maps. I don't wanna focus on that because I'm already doing graphic design stuff for another project. Apologies for any formatting errors, I'm posting this from mobile.
 

guest1492

Member
Apr 28, 2018
350
288
I assume an easy genetics system would mean randomly selecting traits from 2 sets of traits (parents) to create 1 set of traits (child).

You can either do this by creating a JavaScript function or by creating a SugarCube widget. A widget is basically a function except it cannot return anything, but you can always set a variable to your 'return' value and access it outside of the widget.

Example function:
JavaScript:
setup.createChild = function (a, b) {
    const c = clone(a);
    for (const trait of Object.keys(b)) {
        if (random(1)) c[trait] = b[trait];
    }
    return c;
}
Example widget:
Code:
<<widget 'createChild'>><<nobr>>
    <<set _child = clone(_args[0])>>
    <<for _key, _value range _args[1]>>
        <<if random(1)>>
            <<set _child[_key] = _value>>
        <</if>>
    <</for>>
<</nobr>><</widget>>
And you could use them like so:
Code:
<<set $dad = {
    hair: 'brown',
    eyes: 'green',
    skin: 'light',
}>>
<<set $mom = {
    hair: 'black',
    eyes: 'brown',
    skin: 'dark',
}>>
<<set $child1 = setup.createChild($dad, $mom)>>
<<createChild $dad $mom>>
<<set $child2 = _child>>
 
Mar 7, 2018
26
6
I assume an easy genetics system would mean randomly selecting traits from 2 sets of traits (parents) to create 1 set of traits (child).

You can either do this by creating a JavaScript function or by creating a SugarCube widget. A widget is basically a function except it cannot return anything, but you can always set a variable to your 'return' value and access it outside of the widget.

Example function:
JavaScript:
setup.createChild = function (a, b) {
    const c = clone(a);
    for (const trait of Object.keys(b)) {
        if (random(1)) c[trait] = b[trait];
    }
    return c;
}
So... question, is Setup a predefined object in twine or is it something that needs to be created?