Having Trouble with Button Macro

Hello all. I’m new here, new to coding, and new to using Twine. I’ve been working on a story for a week or so now, and I’m having trouble figuring out why I can’t get the button macro to work. I’ll post the code below. I try testing sections in their own passages at first before implementing them into the story.

<<set $coins to 200>>
<<set $melee= []>>

Welcome to the shop! You have <span id=“money”><<print $coins>></span> coins.  What would you like to buy?

<span id=“sold”></span>
<span id=“cash”></span>
<span id=“nocash”></span>
<span id=“nosell”></span>

<<button “Buy Steel Sword for 100 coins”>>
	<<if $coins gte 100>>
		<<set $melee.push(“Steel Sword”)>>
		<<set $coins to ($coins - 100)>>
		<<replace “#money”>><<print $coins>><</replace>>
		<<replace “#cash”>>You bought a Steel Sword!  Don’t forget to visit the Inventory page to equip it!<</replace>>
	<<elseif $coins lt 100>>
		<<replace “#nocash”>>Sorry, you don’t have enough coins for this item.<</replace>>
	<</if>>
<</button>>

There’s another section that is basically identical except that it replaces buy with sell (using the “sold” and “nosell” span ids. I keep getting the error: <<set>>:bad evaluation: invalid or unexpected token in a pop-up on my browser. Any help would be greatly appreciated!

Question answered. Apparently the issue is that I was copying the code I had written on another computer into Twine and it doesn’t like that. I typed everything out again in Twine and it worked exactly as it should.

Looking at the code above, it may be due to using “curly” quotes. Because these won’t work:

<<set $melee.push(“Steel Sword”)>>
<<set $melee.push(‘Steel Sword’)>>

but these will:

<<set $melee.push("Steel Sword")>>
<<set $melee.push('Steel Sword')>>

Because of that, you have to be careful when copying text via word processing programs, since they often change quotes like that.

Glad you got it working! :slight_smile: