NEED HELP WITH SMALL SCRIPT BUG

Posts

Pages: 1
My game: http://rpgmaker.net/games/4506/
I have a blackjack minigame I'm using that functions very well except for an error I'm getting on line 417, this part of code dictates the "dealer's actions however if size=0 it still attempts to divide 100 by size which of course you cannot do, however I know <0 about coding and could seriously use some help.

# Create Values
values = ('2'..amount.to_s).to_a << 'A'
# Get Number of Cards then won't make the dealer bust
number = @deck.number(*values)
# Get Size of Deck
size = @deck.size
# Get Chance of Not Busting
HERE->chance = number * 100 / size
# If chance is less than the riskiness or If value is less than minimum
if (100 - chance <= $game_system.dealer_risk ||
@dealer_hand.total <= $game_system.dealer_min)
# Hit Again
cpu_draw
# Return
If it's a divide by zero error then you can add a check to see if size is zero like so:
if size > 0
  chance = number * 100 / 0
else
  chance = 0
end

Or just set a minimum value for the size to be when assigning it:
size = [@deck.size, 1].max

The .max will always pick the bigger of the two numbers so size can never be smaller than 1.
author=GreatRedSpirit
If it's a divide by zero error then you can add a check to see if size is zero like so:
if size > 0
  chance = number * 100 / 0
else
  chance = 0
end

Or just set a minimum value for the size to be when assigning it:
size = [@deck.size, 1].max

The .max will always pick the bigger of the two numbers so size can never be smaller than 1.

I tried copy pasting it and it didn't work then tweaked like so:
if size > 0
      chance = number * 100 / size
      else
      chance = 0
      end

Works like a charm, you single handedly saved my favorite minigame amigo, you are so getting a thanks in the credits :P
Thanks to: GreatRedSpirit for giving me a fix for a script that would sometimes divide by zero to always divide by zero! Glad it's working now at least :)
author=GreatRedSpirit
Thanks to: GreatRedSpirit for giving me a fix for a script that would sometimes divide by zero to always divide by zero! Glad it's working now at least :)

lol hey you got me on the right path dude
Pages: 1