0 votes
by (2.3k points)

I'm just working on some final building blocks for my game but want to try and have the player statistics factor in to certain dice rolls for stealth, close-combat, intelligence etc. I can make the dice rolls work off a 'roll under $dexterity' etc. But I'm trying to do some even more advanced stuff like

Roll under x (if $class then  a +10, -10 modifier etc applies).

I'm running into 'Bad conditional expression' issues unfortunately. I'm not sure of the final piece of the puzzle...

This is how my code looks:

 


<<set $enemyHP == 34>>
<<set $CurHP == 40>>

Roll a 55 or under!<br>
<span id='dice-outcome'></span>
<span id='dice-button'>
<<button 'Melee!'>>
	<<set $roll to random(0, 100)>>	
	<<if $class == $Observer ($roll-= 30)>> 
	<<if$class == $cqbScout ($roll -= 40>>
	<<if $roll gte 56>>
	<<replace '#dice-outcome'>>
			Your blade misses the enemy bandit, he strikes and you shudder from his blow! Lose 10HP.<br>
			<<set $CurHP -= 10>>
	
		<</replace>>
		<<else>>
		<<if $roll lte 55>>
			<<set $enemyHP -= 17>>
				<<replace '#dice-outcome'>>
				You rolled a $roll. The bandit loses 17 HP.<br>
		<</replace>><</if>>
		<</if>>
			<</if>>
				<</if>>
					<</if>>
						<</if>>
 	<<if $enemyHP lte 0>>
		<<replace '#dice-outcome'>>
			You rolled a $roll. The bandit collapses.<br>
		<</replace>>
		<<replace '#dice-button'>><</replace>> /% remove button %/
		<</if>>
<</button>>
</span>

 

1 Answer

0 votes
by (23.6k points)

What storyformat are you using? Because this looks like Sugarcube but makes no sense in that context.

Setting variables would look like this:

<<set $enemyHP = 34>>
<<set $CurHP = 40>>

And I have no idea what the brackets in the <<if>> are supposed to do. Also you seem to close more <<if>> clauses than you have started.

by (2.3k points)
Yeah it is Sugarcube 2.21 I made a wee error with the ==.

 

The <<if>>  are where I am trying to influence the dice roll with some sort of a modifier on the final outcome of the roll. Basically if someone is a certain class, they get a 'bonus' on the dice roll.
by (23.6k points)

What's the bracket supposed to be? That's not something that works this way in sugarcube. Did you mean to say:

<<if $class == $Observer>> <<set $roll-= 30>> <</if>> 

 

by (44.7k points)

Yeah, the <<if>> macro expects there to only be a conditional expression inside the <<if>> part, so when you do this:

<<if $class == $Observer ($roll-= 30)>> 

the "$class == $Observer ($roll-= 30)" part isn't a valid conditional expression, thus triggering the "Bad conditional expression" error message.

The expression in the parentheses has to be in it's own <<set>> macro, as idling showed above.

Also, instead of replacing "dice-outcome" with the result and then replacing "dice-button" with nothing, you could simplify that by getting rid of the "dice-outcome" span, and just replace the "dice-button" itself with the outcome.

Hope that helps!  :-)

by (2.3k points)
Thanks to you both, I have improved it and got it working!

I tried to get the dice-outcome removed and replaced with dice-button entry but it just made the button vanish after the first roll of the dice. Oh well.
by (23.6k points)
<<nobr>>
<<set $enemyHP to 34>>
<<set $CurHP to 40>>

Roll a 55 or under!<br>
@@#button;
<<button 'Melee!'>>
<<replace "#button">>
	<<set $roll to random(0, 100)>>	
	<<if $class == $Observer>><<set $roll-= 30>><</if>> 
	<<if $class == $cqbScout>><<set $roll -= 40>><</if>>
	<<if $roll gte 56>>
		Your blade misses the enemy bandit, he strikes and you shudder from his blow! Lose 10HP.<br>
		<<set $CurHP -= 10>>
	<<elseif $roll lte 55>>
		<<set $enemyHP -= 17>>
		<<if $enemyHP gt 0>>
			You rolled a $roll. The bandit loses 17 HP.<br>
		<<else>>
			You rolled a $roll. The bandit collapses.<br>
		<</if>>
	<</if>>
<</replace>>
<</button>>
@@
<</nobr>>

 

...