I'm trying to make the leap from Twine 1.0 Sugarcube to Twine 2.0 Harlowe and I'm struggling with variables.
I'm trying to build a version of the old Kingdom or Hamurabi games which require variable manipulation. I know how this is done in Sugarcube but I'm struggling in Harlowe.
I've set the variables likes this:
(set: $money to 40)
(set: $resp to 20)
Money: $money
Respectablility: $resp
test variables
And then go on to test this on the next page:
Repectability: $resp
Money: $money
(if: $money > $resp) [You are getting more respectable (set: $resp to $resp + $money)]
(if: $money < $resp) [You are getting less respectable (set: $resp to $resp - $money)]
(else: ) [Your respectability is the same]
Your new Respectability is $resp
I have also tried the following for the third line:
(if: $money = $resp)
(if $money is $resp)
It works where $money is less than $resp but not the other way around. The lines of code should do an identical job as far as I can see but they don't.
So two novice questions:
* Am I right in thinking that the square brackets are used to contain the expression? In other words, this is the code that should be run if the condition is met?
*Is the problem something to do with placement of lines?
Any help massively appreciated!
Carl.
Comments
Your problem is that your second (if:) should be an (elseif:) instead. For example:
Also, when modifying a variable's current value, you may replace instances of the variable after the first with the keyword it. For example: You don't have to do that, but it does save some typing.
Please use the C button in the comment area's toolbar to wrap your code examples in code tags.
There are a number of errors/issues with the above:
a. You are missing the requires colon after the macro name in the second line, so that line will output the values of the $money and $resp variables.
b. A single equals sign (=) means assignment in Javascript (and Harlowe script), you use either double (==) or triple (===) equal signs when doing a comparison.
c. Harlowe does not support assigning values to variables within the conditional part of the (if:) macro.
d. Harlowe does not support using double (==) or triple (===) equal signs when doing a comparison in an (if:) macro, it uses the is keyword operator.
e. Based on all the above the two lines are not equivalent.
There are a number of errors/issue within your test variables passage: 1. You have an Invalid space character between your (if:) macro's and their assocated hooks [...]
2. Because the second (if:) macro is not an (else-if:) the two (if:)'s are considered mutually exclusive, and because you are changing the value of $resp in the first (if:) the condition in both (if:) macros end up being true.
a. $money (40) is greater than $resp (20) so $rest is changed to equal 60 (20+40)
b. $money (40) is less than $resp (60) so $rest is changed to equal 20 (60-40)
3. The (else:) macro is only associated with the second (if:) macro.
4. (not an error as such) You have an unnecessary space character in the (else: ) macro.
Your example should look something like the following:
I clearly have a lot to learn!
Back to experimenting and feeling my way through the docs I guess.
Thanks again.