0 votes
by (170 points)

Hi guys,

Thanks for reading my question! Currently I am following this guide to implement a battle system. However the system seems to be made for another code then sugarcube. Now I have been able to implement a decent amount already but am stuck on the enemy attack part. This is really a head scratcher but I am sure that it is something I must have overlooked right now.

<<if $enemyHealth gte 1)>>
	<<set $enemyHit to random(0,$chickenattack) - (random:0,$shield)>>
	The $enemyName ATTACKS YOU for $enemyHit damage!
	<<set $health to $health - $enemyHit>>
	<<set $points to $points + $enemyHit>>
	You have $health health left.
	<<if $health gte 1>>
		[[Attack]]
	<<elseif $health lte 0>>
		[[You lost]]
	<</if>>
<<else>>
	You have defeated the $enemyName. +10 pts!
	<<set $points to $points + 10>>
	<<set $randomGold to random(5,10)>>
	<<set $gold to $gold + $randomGold>>
	You gained $randomGold gold! You now have $gold gold.
	You have $health health.
	[[Leave|tower]]
	
<</if>>

Where is the unexpected token if any?

Friendly regards,

Sneezy

1 Answer

+1 vote
by (68.6k points)
selected by
 
Best answer
The error tells you where it is, in an <<if>>, and describes the problem, which is an erroneous right parenthesis.  Check the first line (the first <<if>>) in your sample, there's a right paren (")") at the end of the conditional where there shouldn't be.

Beyond that.  You haven't replaced all instances of Harlowe's (random:) macro.  Check the second line (the first <<set>>) in your sample.
by (170 points)
Thanks! Seems like I have been staring at it too long to be blinded by such simple mistakes. Also new to convert from Harlowe to Sugarcube. I'm gonna brush up on some basics.

Thanks again!
...