Hi everyone, I've started using Twine a few weeks ago now, and I think I'm getting better, but I am still very much a novice. I have read the Sugarcube documentation and everything, but a lot of it is still quite mysterious to me.
Basically, I've created several "marketplace" passages where you can buy various items, like so:
(Product description here)
/* The following variables and stuff are placeholders. */
<<if $player_money >= 500>>\
Would you like to buy this product?
<<linkreplace Buy "Product in question">>\
<<set $player_money -= 500>>\
Thank you for shopping here!
<<set $productinquestion_count += 1>>\
<<set $inventory_count += 1>>\ /* This is for the inventory system I have, no need to pay attention. */
You receive a "Product in question"
<</linkreplace>>\
<<else>>\
You don't have enough money to purchase the "Product in question".
<<endif>>\
[[Back to main marketplace here]]
The issue is that later on in my game, you can accumulate enough money where buying several of the item can be interesting. This system, while functional, requires the player to click back through menus/passages to get to the page again.
So what I'm looking for is a way to make a link that offers itself as an option if the player has enough money (with a thank you message to boot), or refuses payment if not. My original idea was using the <<link>> macro as opposed to the <<linkreplace>>, but it doesn't stop when the player overspends, and doesn't update the passage at all until you switch passages (unless I'm missing some kind of limit). I also tried using the <<link>> as a link to the passage itself, but I lose the message that way. I also briefly attempted some <<for>> looping:
<<if $player_money >= 100>>
Would you like to buy this product?
<<for $player_money >= 100>>\
\
<<if $player_money < 100>>\
You don't have enough money to purchase the "Product in question".
<<else>>\
\
<<link Buy>>\
<<set $player_money -= 100>>\
Thank you for shopping here!
<<set $productinquestion_count += 1>>\
<<set $inventory_count += 1>>\
You receive a "Product in question".
\
<</link>>\
<<break>>\
\
<<endif>>\
\
<</for>>\
<<else>>\
You don't have enough money to purchase the "Product in question".
<<endif>>
I must confess that I'm really not sure how to use loops, as I'm very new to these basic programming concepts (as you can probably tell from above :P) ; and I have no idea if it can even apply to my case.
I don't need a <<for>> loop necessarily, however I would like to know if what I'm looking to achieve is possible, and if so, how. I'd appreciate any help!