Hi all,
I am just starting out using Twine 2 (using story format Harlowe 2.0) and still getting hang of a few things. I will apologise immediately if I use the wrong terminology when referring to things. (Still learning).
I have generally been able to find answers to issues, however, I cannot seem to find if I can print the result of a variable to 2 decimal places, such as printing 13.25 instead of a whole number. The only methods that I can see in the wiki only show how to do a whole. Is there an option to 2 decimals?
Any guidance would be great
Comments
I have been using the string containing numerals, as this is what I found was used and taught in tutorials. But I guess they had been using whole numbers and I went with numbers with decimals, which doesn't seem to be as friendly.
I will have to look at how to use number values next.
An easy rule of thumb is if you ever plan on doing math with a value, then it should be a number. If no math will ever happen with a value, then using a numeric string is probably okay.
Currently I am seeing in tutorials (just random tutes on peoples blogs and on youtube) that show the following expressions: (this is just an example)
Passage 1
(set: $name to 5)
Passage 2
(set: $name to $name + 5)
which now makes $name = 10.
They have been using this for HP/gold increases/decreases (or other numbers). So I assumed that this would be okay.
I do understand what you are saying about numerals variables vs math numbers. I just haven't come across how to set it in numbers instead of numeral string. As the wiki is not really clear enough for me at such a beginner level. I have tried what I thought it was trying to say, but have been incorrect.
That is the correct way to set a number. The addition is correct as well, though, in Harlowe you may also write that as: Regardless. If that's what you've been doing, then you should be okay.
For an example of what I meant by a numeric string: My earlier warning was about the final set (2b). I cannot count the number of times we've seen people attempting to do math on (numeric) strings like that because they simply didn't know the difference.
As an example of the <Number>.toFixed() method in action: (tested in both Harlowe v1.2.3 & v2.0.0) Which outputs the following:
Apologies
Thank you.
Yes, I had been using them as numbers. Apologies, I knew I would get terminologies mixed up.
This has been an amazing help thank you