Jump to content

Stupid little program that won't work right.


 Share

Recommended Posts

So, this is the program that I have been tinkering with. It is just something that I was trying to quickly whip up to generate a character for D&D. I tried to do a search of the forum for anything similar but I didn't find anything. I have tried to set it up for various systems in that I have a variable number of die rolled, and number of stats needed. Further, my DM gives us a minimum stat. (nothing lower than 10 in his case, nice guy that he is :) ) It seems to be the minimum stat that is giving me issues. Everything else seems to work well. But when it tries to reroll the stat if it is below the minimum it gives me way too many stats. Anyway, any help would be appreciated. (It is probably something stupid that I missed. It usually is... ;) )

CODE

$dice = Inputbox ("Stats", "How many die?")

$stat = InputBox ("Stats", "How many stats do you need?")

$min = InputBox ("Stats", "What is your minimum stat?")

$i = 0

$s = 0

While $s < $stat

$k = (Random (1,6,1) * $dice)

If $k < $min then

$k = (Random (1,6,1) * $dice)

FileWriteLine ("Stats2.txt", "Stat " & $k)

Else

FileWriteLine ("Stats2.txt", "Stat " & $k)

$s = $s + 1

EndIf

WEnd

Link to comment
Share on other sites

You were recalculating improperly. If your If/Then test fails, just loop again until it passes. Simple. Enjoy.

Not only that, this one gives a better result by rolling the dice properly instead of rolling one die and then multiplying.

<code removed, see next post>

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Fixed an infinate loop bug and added an "=" so the minimum stat can be a possible result.

Opt("MustDeclareVars", 1)
Dim $intCount, $intMinStat, $intNumDice, $intNumRolls, $intNumSides
Dim $TEMP
$intNumDice = InputBox("Stats", "How many dice to roll at once?", "3")
If @error Then
    Exit
EndIf
$intNumSides = InputBox("Stats", "How many sides are on the dice?", "6")
If @error Then
    Exit
EndIf
$intNumRolls = InputBox("Stats", "How many times do we roll the dice?", "6")
If @error Then
    Exit
EndIf
$intMinStat = InputBox("Stats", "What is your minimum stat?", "0")
If @error Then
    Exit
EndIf
If $intMinStat > $intNumSides * $intNumDice Then
    MsgBox(0, "Error 420", "Error:  Minimum Stat is above maximum dice roll!")
    Exit
EndIf
$intCount = 1
While $intCount < $intNumRolls + 1
    $TEMP = 0
    For $loop = 1 To $intNumDice
        $TEMP += Random(1, $intNumSides, 1)
    Next
    If $TEMP >= $intMinStat Then
        ConsoleWrite("Stat " & $intCount & " " & $TEMP & @LF)
        $intCount += 1
    EndIf
WEnd

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...