LenAnderson/SillyTavern-LALib

Seemingly a problem with the while loop.

Closed this issue · 1 comments

I'm making a system where the silly tavern will DM using the WoD style of dice rolling. Here is a quick description of the relevant rules. role a number of ten sided dice. dice above a certain amount are successes. When ten is rolled you can roll again to potentially gain additional successes. Here is the code that models this behavior.

/setvar key=successes 0|
/setvar key=dice 5|
/setvar key=goodroll 0|
/while left={{getvar::dice}} rule=gt right=0 {:
	/if left={{getvar::dice}} rule=gt right=0 {:
		/incvar goodroll
	:}|
	/setvar key=roll {{random::1::2::3::4::5::6::7::8::9::10}}|
	/if left={{getvar::roll}} rule=gte right=6 {:
		/incvar successes
	:}|
	/if left={{getvar::roll}} rule=lt right=10 {:
		/decvar dice
	:}
:}|
/echo 
dice left:{{getvar::dice}}
successes:{{getvar::successes}}
good rolls:{{getvar::goodroll}}

When this snippet is run the result is dice will be a negative number usually between -90 and -80 when logically it should be 0.
Essentially what it seems is happening is that when /while does the gt test it continues instead of breaking the loop when left>right evaluates to false until it hits the hard limit.
I've inserted a counter to see test if "gt" is working properly in other commands.

/if left={{getvar::dice}} rule=gt right=0 {:
	/incvar goodroll
:}

the final result of goodroll is sane (above 5 and usually below 10).

/while is not LALib, it is ST core.
You need to use just the var name in while, not the macro.