Looping dice rolls?

im reading somewhere that people are coding dice roll subroutines with a loop.

my question is the relevance of setting that loop.
would the subroutine be a one time thing cause im trying to incorporate said diceroll into a combat mechanic like fighting fantasy style games.

anyone with similar endeavors?

It doesn’t need to be a subroutine for simple dice rolls. The basic formula would be:

*rand roll num_dice (num_dice * num_sides)

i tried this a while back, but it just doesnt seem to stick anyways am experimenting with subroutines but now theres the problem of values changing for some reason everytime the stat screen is accessed

I have to admit, I’m not sure what you’re asking … like at all?
What do you mean when you say “with a loop”?
Then you want the “relevance” (which is a fairly ambiguous term that doesn’t really tell me what kind of answer you’re expecting) of “setting that loop” (what loop?).
And I have no idea what you mean by “one time thing”? No, you can use it as many times as you want, if you code it properly (which is the whole point of having a subroutine)?

1 Like

Subroutine actually allows you to reuse content; that is, to call a code repeatedly as you wish, anywhere you want.

Here’s how it looks like

*label loop
Hey, yo. I wanna
*gosub loop

But I'm not done yet, so I gonna
*gosub loop

Wait, one more
*gosub loop
That should produce

Hey, yo. I wanna

But I’m not done yet, so I gonna

Wait, one more

On another note, accessing stats screen will reroll the dice. This has been a “bug” for a long time as fixing it requires a big attention.
In the meantime, CoG is focused on their omnibus.

Well. This post will be deleted but I wish to add that i do use a die rolls subroutine in my codes. You see. Dice rolls just return numbers but for one of my codes (It was for simulate a “draw a card” event so there was another loop that check for repeated sorted letters in order to avert the same “card” being pulled twice ) I was needing a row that return letters istead of numbers so I did it like:

*comment this loop return a random letter...
*comment === I already declare a global variable that receives char It's name is "letter"

*label init_loop1

*temp die 0

*rand die 1 15

*if (die = 1 )
  *set letter "a"
*if (die = 2 )
  *set letter "b"

*if (die = 3 )
  *set letter "c"

*if (die = 4 )
  *set letter "d"

*if (die = 5 )
  *set letter "e"

*if (die = 6 )
  *set letter "f"

*if (die = 7 )
  *set letter "g"

*if (die = 8 )
  *set letter "h"
*if (die = 9 )
  *set letter "i"

*if (die = 10 )
  *set letter "j"

*if (die = 11 )
  *set letter "k"

*if (die = 12)
  *set letter "l"

*if (die = 13)
  *set letter "m"

*if (die = 14)
  *set letter "n"

*if (die = 15 )
  *set letter "o"


Test the Letter generated is: ${letter}


I hope it will be of use.

Please Ignore my Last post. Iam so dumb! There is a LOT better ways to do that. My entire former code example could be summarized in these lines:

*label init_loop1
*set Attrib2 "abcdefghijklmnopqrstuvwxyz"

*comment this '*if' breaks the loop

*comment *if (Attrib0>number_of_loops)
*comment   *return    

*temp die 0
*temp letter ""

*rand die 1 Number_of_loops

*gosub insert

*set Attrib2 letter

Test Letter generated: ${Attrib2}

*comment ============== repeat! ===================
*label insert

*set letter "${Attrib2#die}"


As you see. The variable Attrib2 (Attribute number 2) return a random letter in the sequence. You cam even write a routine to “shuffle” a sequence before the code pick one adding another useless layer of randomness to this useless code!

1 Like