Increment variable not working

Hi,

I’m trying to add an increment system on a variable in chapbook.
Let’s say I have the variable money set to 10 (money: 10) and i want on next passage to increase it by 1.

Looking at the documentation I should do money: money + 1 but when I do that I end up with money = 101 instead of 11. And if I continue it’ll just go 1011, 10111 etc…

BUT when I do money: money - 1 it’s working and print money = 9… What’s going wrong ?

Sounds like it’s treating it as a string: + is used both for adding numbers and appending to strings. But if you subtract, then - is only used for subtracting numbers so it treats it as a number.

I’m not sure why it would be a string in the first place: can you share which version of Twine and which version of Chapbook you’re using? And copy/paste your exact code so we can see it?

Thanks for the fast answer !

I’m using Twine 2.7.0 and Chapbook 1.2.3.

Start:

config.body.transition.duration: "350ms"
config.header.left: ""
config.header.center: ""
config.header.right: ""
config.style.backdrop: "#4A3F35"
config.style.page.verticalAlign: "top"
config.footer.center: "{back link} | {restart link}"
config.footer.left: ""
config.footer.right: ""
config.style.page.link.color: "blue-7"
config.style.page.link.font: "none"
config.style.page.link.active.color: "blue-3"
config.style.page.link.active.font: "underline"
config.style.page.color: "gray-2 on gray-9"
--
[align center]
title
[align left]
Hello

[[Beginning]] 
[continue]

Beginning:

config.header.center: "<img class='hf' src='img/header.jpg'>"
config.header.left:""
config.footer.center: "<img class='hf' src='img/footer.jpg'>{back link} | {restart link}"
config.footer.left: ""
config.footer.right: ""
money: "10"
--
blabla

You have {money}$

[[keep talking]]

keep talking:

money: money + 1
--
blabla

Money increased by one, you now have {money}$

[[continue]]

Continue:

money: money - 1
--
You lost 1$ and now have {money}$

Using quotes sets the variable to a string. To set it to a numerical value, use 10 without the quotes:

money: 10
1 Like

Thank you :sweat_smile: