How to make a credit system?

hello, I’m new to coding and twine and I’m making my first game I want a shop that players can buy from, but I need a credit system, so I don’t have to make everything free

You can use a Story variable to track how much “credit” the Reader has, and update that variable when every its value needs to increase or decrease.

The (set:) macro is used to assign/change the value variable. The initialisation of the variable should be done within your project’s startup tagged passage.

(set: $credits to 0)

Each time the Reader earns “credits” you would increase the current value of the variable…

(link: "Do some paid work")[
   (set: $credits to it + 25)
]

And each time the Reader spends credits you would decrease the current value of the variable…

(link: "Buy the thing")[
   (set: $credits to it - 10)
]

You can use one of the (if:) family of macros to determine if the Reader has enough credits to pay the required cost…

(if: $credits >= 10)[
   (link: "Buy the thing")[
      (set: $credits to it - 10)
   ]
]
(else:)[You don't have enough credits to by the thing]
2 Likes