If-statement in a link or alternate solution?

Twine Version: 2.3.9
Story Format: 2.31.1

I imagine the answer to my dilemma is probably not that complicated but… I have made a collection of 4 items in a game, and I want the player to get a small benefit if he/she has all four. The individual items are simple variables written in Sugarcube (nothing fancy; $oneill, $carter, $jackson, and $tealc). The game already checks to see if the player has the item or not, and whether he/she can afford the individual item, and displays the same text but without the link if they can’t. Normally, I’d simply add the +=1 to $Charisma in the link but since this hinges on having all four items, I’m not really sure how to handle it.

Can I add an <<if>> statement in the [[link]] or should I use a <<link>> instead, and if so, how do I write that so it works? I have also considered the option of simply expanding the choices with additional <<if $oneill eq 1 and $carter eq 1 and $jackson eq1>>[[Buy the Teal'c figure|passagename][$cash-=x; $charisma+=1]] for each of them but it seems like a lot of work. What’s the easiest way to this guys, not including JS?

You can add an <<if>> statement within a link if you use the <<link>> macro.

If I understand correctly, you want to increase Charisma by one when the player byus the fourth item, no matter which item it actually is. To achieve that, you can, for example, put <<set $figures to 0>> in your StoryInit (which will count the total number of items owned by the player) and make the following “buy” links:

<<link "Buy the Teal'c figure" "passagename">><<set $cash -= x>><<set $tealc to 1>><<set $figures += 1>><<if $figures == 4>><<set $charisma += 1>><</if>><</link>>

I tested and it works wonderfully :blush: Many thanks