So here's the dealio,
I am using the <<set $var1 = Math.floor(Math.random()*3)>> code, to allow me to use a kind of hit chance thing. I need to replace the 3 with a variable, but whenever I try it doesn't work. I am using it for this piece of code-
<<set $hit = Math.floor(Math.random()*$dexterity)>>
<<if $hit == "0">>Text<<set meleewep to "holylongsword">>
<<endif>>
<<if $hit== "1">>Text<<set $wounds to "+1">> <<set meleewep to "holylongsword">> <<endif>>
<<if $hit == "2">>Text <<set $wounds = "2">> <<endif>>
<<if $wounds gte "6">>death scene<<endif>>
Also, would it be possible to use two variables in this? For example, <<set $var1 = Math.floor(Math.random()*$dexterity*strength.)>>
Thanks guys,
Bladezy Boo
Comments
$dexterity
is set by that point? If it's not, then you'll only ever get0
orNaN
out of the expression (depending).Additionally, you're conflating numbers and numeric strings. Don't do that.
- Numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Numeric strings: "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
IOW, stop quoting your numbers.Finally, just use the
random()
function built into the story formats (docs: vanilla formats or SugarCube). For example, these will give you the same0(n-1)
range that you're using now: These would, instead, yield the same basic range but starting at1
(i.e.1n
):It took me a while to fix a few errors, but that was due to missing $signs.
Thanks so much,
Bladezy Boo
P.S,
Would you happen to know how I would go about making a statement that said if a variable was between 10 and 50, it would do something, but if it was more or less than 10/50, then it wouldn't?
(note: using TWEE notation, the line starting with a double colon '::' represents a new passage with a passage title as indicated.
Without you, I might never be able to finish this. Thanks