0 votes
by (430 points)
closed by

Hi! I'm trying to find a solution to a problem that I've been trying to solve this weekend but unfortunately I wasn't able to make it work so here I am. (I'm using sugarcube 2.1.3)

First of all, I mustt say that I'm trying to implement a combat system quite unique (at least I didn't find something similar to it). I will leave the code:

 

<<set $tropas = 5>>
<<set $vest = 5>>   <-- strategic advantage
<<set $variable1 = 100>> <-- just a random number I'm using in the denominator
<<set $moralpueblo = 45>> <-- people's morale
<<set $variable02 = $moralpueblo / 2>>
<<set $variable03 = $vest * 2.5>>
<<set $fuerzatropas1 = $variable02 + $variable03 + $tropas>>
<<set $fuerzatropas = $fuerzatropas1 / $variable1>>
<<set $fuerzatropas2 = $fuerzatropas>>

(That's the code for the player)

(And this is the code for the bandits)

<<set $variable08 = 115>>
<<set $moralbandidos = 50>>
<<set $vest2 = 0>>
<<set $tropasbandidos = 65>>

<<set $variable02 = $moralbandidos/ 10>>
<<set $variable03 = $vest2 * 2.5>>

<<set $fuerzabandidos1 = $variable02 + $variable03 + $tropasbandidos>>
<<set $fuerzabandidos = $fuerzabandidos1 / $variable08>>
<<set $fuerzabandidos2 = $fuerzabandidos>>

In the specific passage I'm trying to this:

Con la llegada del amanecer, el panorama en lo que hasta entonces era una prometedora ciudad se ha tornado desolador: casas quemadas, cuerpos esparcidos en torno a las murallas del campamento y un silencio sepulcral, son las secuelas de una contienda que <<if $fuerzatropas2 >= $fuerzabandidos>>a pesar de haber dejado(...) [[Siguiente.|capitulo1-45][$moralpueblo += 5; $fama +=1;$tropas -= 6]]
<</if>>
<<if $fuerzabandidos < $fuerzatropas2>>se ha saldado con la muerte de una gran cantidad de hombres buenos y honrados cuyas vidas tenían por delante un futuro prometedor(...)[[Siguiente.|capitulo1-45][$moralpueblo -= 5; $tropas -= 12]]
<</if>>

And the problem comes when I tried it: it doesn't show the text after the "if" macro, probably because I'm comparing 2 variables that aren't numbers or maybe because I'm too stupid to find out what's really causing such in-game behavior.

Thanks beforehand!

closed with the note: Question answered

1 Answer

+1 vote
by (68.6k points)
selected by
 
Best answer

In both cases within your example, neither of the <<if>> conditionals evaluate to true.  Due to the numbers involved, $fuerzatropas2 ends up with the value 0.4, while $fuerzabandidos ends up with, approximately, 0.8695652.

0.4 is not greater-than-or-equal to 0.8695652, neither is 0.8695652 less-than 0.4.

You only need one <<if>> with an <<else>> there since your conditions are in direct opposition.  For example:

<<if $fuerzatropas2 >= $fuerzabandidos>>a pesar de haber dejado …
<<else>>se ha saldado con la muerte …
<</if>>

 

...