none
roll dices RRS feed

  • Question

  • As I understand the learning lessions this below program should work, only it dosen't.

    What I try to do is to roll four dices with six sides for six attributes for a game. Roleplayers call it 4d6 drop lowest.

    Of course I could always use getrandomnumber in 24 lines but would prefer to rationalize the prosess with the For x to y routines. Anyone seeing why this don't work?

    TextWindow.WriteLine("Now let us get you some attributes. 4d6 drop lowest is used.")
    nd = 6 ' six sided dice
    calc = 0 ' must start at zero
    For six = 1 to 6 ' the six attributes
      For four = 1 to 4 ' the four dices
        grn(four) = Math.GetRandomNumber(nd) ' roll the dice
        calc = calc + grn(four) ' summarum the four dices
      EndFor
     min(1) = Math.Min(grn(1), grn(2)) ' get the lowest number of dice 1 and 2
     min(2) = Math.Min(grn(3), grn(4)) ' get the lowest number of dice 3 and 4
     min(3) = Math.Min(min(1), min(2)) ' get the lowest number of the above two lines
     attr(six) = calc - min(3) ' give the result of 4d6 drop lowest to all 6 attributes
     TextWindow.WriteLine("Your " + six + " attribute is; " + attr(six) + ". ")
    EndFor

    Sunday, December 9, 2012 8:35 PM

Answers

  • I am familiar to role-playing. I made one modification to the above code. I added 'calc = 0' to line 5 because you want the sum of the 3 highest rolls out of 4 ,not including previous rolls, only the one that is happening now.

    TextWindow.WriteLine("Now let us get you some attributes. 4d6 drop lowest is used.")
    nd = 6 ' six sided dice
    calc = 0 ' must start at zero
    For six = 1 to 6 ' the six attributes
      calc = 0 'reset to zero
      For four = 1 to 4 ' the four dices
        grn[four] = Math.GetRandomNumber(nd) ' roll the dice
        calc = calc + grn[four] ' summarum the four dices
      EndFor
      min[1] = Math.Min(grn[1], grn[2]) ' get the lowest number of dice 1 and 2
      min[2] = Math.Min(grn[3], grn[4]) ' get the lowest number of dice 3 and 4
      min[3] = Math.Min(min[1], min[2]) ' get the lowest number of the above two lines
      attr[six] = calc - min[3] ' give the result of 4d6 drop lowest to all 6 attributes
      TextWindow.WriteLine("Your " + six + " attribute is; " + attr[six] + ". ")
    EndFor


    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    • Marked as answer by Ivarsen Sunday, December 9, 2012 9:00 PM
    Sunday, December 9, 2012 8:48 PM

All replies

  • Arrays in SmallBasic have indexes within square brackets [] not round brackets ().

    Does this corrected work as you expect:

    TextWindow.WriteLine("Now let us get you some attributes. 4d6 drop lowest is used.")
    nd = 6 ' six sided dice
    calc = 0 ' must start at zero
    For six = 1 to 6 ' the six attributes
      For four = 1 to 4 ' the four dices
        grn[four] = Math.GetRandomNumber(nd) ' roll the dice
        calc = calc + grn[four] ' summarum the four dices
      EndFor
      min[1] = Math.Min(grn[1], grn[2]) ' get the lowest number of dice 1 and 2
      min[2] = Math.Min(grn[3], grn[4]) ' get the lowest number of dice 3 and 4
      min[3] = Math.Min(min[1], min[2]) ' get the lowest number of the above two lines
      attr[six] = calc - min[3] ' give the result of 4d6 drop lowest to all 6 attributes
      TextWindow.WriteLine("Your " + six + " attribute is; " + attr[six] + ". ")
    EndFor

    Sunday, December 9, 2012 8:41 PM
    Moderator
  • I am familiar to role-playing. I made one modification to the above code. I added 'calc = 0' to line 5 because you want the sum of the 3 highest rolls out of 4 ,not including previous rolls, only the one that is happening now.

    TextWindow.WriteLine("Now let us get you some attributes. 4d6 drop lowest is used.")
    nd = 6 ' six sided dice
    calc = 0 ' must start at zero
    For six = 1 to 6 ' the six attributes
      calc = 0 'reset to zero
      For four = 1 to 4 ' the four dices
        grn[four] = Math.GetRandomNumber(nd) ' roll the dice
        calc = calc + grn[four] ' summarum the four dices
      EndFor
      min[1] = Math.Min(grn[1], grn[2]) ' get the lowest number of dice 1 and 2
      min[2] = Math.Min(grn[3], grn[4]) ' get the lowest number of dice 3 and 4
      min[3] = Math.Min(min[1], min[2]) ' get the lowest number of the above two lines
      attr[six] = calc - min[3] ' give the result of 4d6 drop lowest to all 6 attributes
      TextWindow.WriteLine("Your " + six + " attribute is; " + attr[six] + ". ")
    EndFor


    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    • Marked as answer by Ivarsen Sunday, December 9, 2012 9:00 PM
    Sunday, December 9, 2012 8:48 PM
  • Thanks for the answer, I overlooked the [ ( symbols. This is solved then.
    Sunday, December 9, 2012 8:59 PM