Twine Version: 2.8.1
Story Format: Harlowe 3.3.8
Greetings! I am very new to Twine and am currently working on my first project. I’ve had a look through the forum, but couldn’t find a similar post, which is why I’m writing this. Please excuse if something similar has already been asked.
I’d like to write a quasi text based RPG, so naturally, I want to include a “character creation” screen at the beginning. On this page the user can choose a race for their character, adjust some abilitiy stats and give their character a name, all very reminiscent of classic rpg’s like D&D. I’ve done the ability stats and choosing the name and I’m quite happy with the results, but choosing a race for the character is giving me a hard time.
For referance, the code for adjusting the stats (which works perfectly fine) looks like this:
<==
||||=
Strength: {
(link-repeat: "|+|")[
(if: $points > 0)[
(set: $str to it + 1)
(set: $points to it - 1)
(replace: ?strengthStat)[|strengthStat>[$str]]
(replace: ?pointsStat)[|pointsStat>[$points]]
]
] |strengthStat>[0]
(link-repeat: "|-|")[
(if: $str > 0)[
(set: $str to it - 1)
(set: $points to it + 1)
(replace: ?strengthStat)[|strengthStat>[$str]]
(replace: ?pointsStat)[|pointsStat>[$points]]
]
]
}
Intelligence: {
(link-repeat: "|+|")[
(if: $points > 0)[
(set: $int to it + 1)
(set: $points to it - 1)
(replace: ?intStat)[|intStat>[$int]]
(replace: ?pointsStat)[|pointsStat>[$points]]
]
] |intStat>[0]
(link-repeat: "|-|")[
(if: $int > 0)[
(set: $int to it - 1)
(set: $points to it + 1)
(replace: ?intStat)[|intStat>[$int]]
(replace: ?pointsStat)[|pointsStat>[$points]]
]
]
}
Dexterity: {
(link-repeat: "|+|")[
(if: $points > 0)[
(set: $dex to it + 1)
(set: $points to it - 1)
(replace: ?dexStat)[|dexStat>[$dex]]
(replace: ?pointsStat)[|pointsStat>[$points]]
]
] |dexStat>[0]
(link-repeat: "|-|")[
(if: $dex > 0)[
(set: $dex to it - 1)
(set: $points to it + 1)
(replace: ?dexStat)[|dexStat>[$dex]]
(replace: ?pointsStat)[|pointsStat>[$points]]
]
]
}
{
(link-repeat: "|Reset Points|")[
(set: $str to 0)
(set: $int to 0)
(set: $dex to 0)
(set: $points to 15)
(replace: ?strengthStat)[|strengthStat>[$str]]
(replace: ?intStat)[|intStat>[$int]]
(replace: ?dexStat)[|dexStat>[$dex]]
(replace: ?pointsStat)[|pointsStat>[$points]]
]
}
(text-style:"underline")[Remaining Points: |pointsStat>[15]]
The issue that I’m having is with the selection of the character’s race. I’ve made a dropdown menu with three options (Human, Dwarf and Elf). When the user selects one of these options 2 things should happen:
- A descriptive text should be displayed
- I’d like the choice of character race to influence the ability stats (ie. if “Human” is chosen give a +1 bonus to all stats (strength, intelligence and dexterity), if “Dwarf” is chosen get rid of the Human bonus and instead give a +2 bonus to strength and -1 to intelligence, if “Elf” is chosen get rid of any previous bonus and give a +2 to dexterity and -1 to strength)
The first works just fine, but number 2 is giving me lots of headache, and I just can’t make it work…
The code I wrote for this looks as follows:
Choose your Race: [(dropdown: 2bind $race, " ", "Human", "", "Dwarf", "", "Elf")]
{
(set: _Hbonus to 1)
(set _HumanSelected to false)
(set: _DwarfSelected to false)
(set: _ElfSelected to false)
|Human>[(event: when $race is "Human")[
(if: not _HumanSelected)[
(set: $str to it + _Hbonus)
(set: $int to it + _Hbonus)
(set: $dex to it + _Hbonus)
(set: _HumanSelected to true)
(set: _DwarfSelected to false)
(set: _ElfSelected to false)
(replace: ?strengthStat)[|strengthStat>[$str]]
(replace: ?intStat)[|intStat>[$int]]
(replace: ?dexStat)[|dexStat>[$dex]]
]
(replace: ?raceText)[
Some descriptive text about Humans.](rerun: ?Human)]]
|raceText>[]
}
The problem I’m having is that the bonuses are cumulative, and whenever a new option is chosen from the dropdown menu, the values of $str, $int and $dex just keep increasing. I don’t know how to make it so that the +1 bonus to all stats from the “Human” choice is reverted when another selection is made (I hope that explanation makes sense). What am I doing wrong/how can this be fixed?
EDIT: Also, I just found out that choosing any option in the dropdown menu makes all other interactable elements un-interactable? Meaning that the user can’t adjust their stats anymore once they used the dropdown menu, as the link-repeat links stop working… Why is that and how can it be fixed?
P.s.: To avoid redundancy and prevent this post from getting too long, I omitted the code I have for Dwarves and Elves which is exactly the same as above with a few words changed.
Thanks a lot in advance!