Hello,
I am trying to learn the more in-depth parts of Harlowe 3.3.8, and I am using the manual as a jumping off point. Essentially taking the examples in the manual and trying to figure out how they work by messing around with them (i.e. breaking them) and/or adding new elements. I am very much not programming minded, I struggle with figuring out how to translate snippets into implementation, in that regard the manual is both a blessing and a curse, I wouldn’t mind if almost every example was expanded upon and snippets given more context. I say this to ask if you do answer, please be patient with me, and I am sorry for how much hand-holding I require.
Anyway, sorry, in the manual under (Macro:) is the following example:
(set: $charSheet to (dm: "name", str, "HP", num, "poison", num, "heartbreak", bool))
(set: $healthSummary to (macro: $charSheet-type _stats, [
This text inside the macro is not displayed during the game.
(set: _TheyAre to _stats's name + " is ")
Dead characters get a single, pithy line.
(if: _stats's HP <= 0)[(output: _TheyAre + "deceased.")]
Living characters get specific status conditions referred to.
(output-data:
_TheyAre + "in " + (cond: _stats's HP > 50, "fair", "poor") + " health." +
(cond: _stats's poison > 0, " " + _TheyAre + "poisoned.", "") +
(cond: _stats's heartbreak, " " + _TheyAre + "heartbroken.", "")
)
]))
(set: $steelyStats to (dm: "name", "Steely", "HP", 80, "poison", 0, "heartbreak", true))
($healthSummary: $steelyStats)
which btw, if the first output should be changed to output-data, as if Steely dies in this example, an error is returned instead of the “deceased” if ‘HP’ reaches 0.
And this is in my startup passage:
(set: $steelyStats to (dm: "name", "Steely", "HP", 80, "poison", 0, "heartbreak", true))
To test how to change stats, I made the following links back to this same sheet but with set macros attached
(link: "gain 40 health")[(set: $steelyStats to (dm-altered: via its value + 40 where its name is 'HP', $steelyStats))[(go-to:"Character Sheet")]]
(link: "lose 40 health")[(set: $steelyStats to (dm-altered: via its value - 40 where its name is 'HP', $steelyStats))[(go-to:"Character Sheet")]]
(link: "gain poison")[(set: $steelyStats to (dm-altered: via its value - 5 where its name is 'poison', $steelyStats))[(go-to:"Character Sheet")]]
(link: "lose poison")[(set: $steelyStats to (dm-altered: via its value + 5 where its name is 'poison', $steelyStats))[(go-to:"Character Sheet")]]
I am wanting to do one of two things, preferably I would like to learn how to do both.
- if ‘poison’ is - 5, then when I click the link or upon re-entry to the passage, I would like ‘HP’ to decrease by 5, if ‘poison’ is - 10 decrease ‘HP’ by 10
- Along with this one, I would like to learn how to set a maximum, because you can only be so poisoned, so there shouldn’t be the ability to go above 0 poison.
What I have written up myself so far but it doesn’t work (I know part of the reason is that there’s nothing after value but I don’t have the foggiest what else to put there and achieve my goal):
(if: $steelyStats's (dm-names: "poison") is > 0)[(set: $steelyStats to (dm-altered: where its name is 'poison' via its value where its name is 'HP'))]
and/or
- How to use a lambda to set a boolean. In a different iteration, I attempted to set poison to a boolean, but found I couldn’t figure out how to use the (dm-altered:) to change the value to a ‘true’ for poisoned or a ‘false’ for not.
- For this iteration, I would like a set value to be removed from ‘HP’ every time a turn is taken and the ‘poison’ is ‘true’.
I attempted to do change the boolean of heartbreak with this code:
(link: "find a new love")[(set: $steelyStats's (dm-names:'heartbreak') to false)[(go-to:"Character Sheet")]]
But if I click it, Steely is still ‘heartbroken’ and I get an error that states:
A datamap (with “name”, “HP”, “poison”, and “heartbreak”) can only have string data names, not an empty variable.
To summarize:
- How do I check the value of a datamap entry (e.g. ‘poison’) and if 1) it is not zero then change another datamap entry’s (e.g. ‘HP’) value by the same amount or 2) it is ‘true’ then change another datamap entry’s value by a set amount
- How can I change the value of a datamap entry when it is a boolean