Rounding numbers up or down.[resolved]

Started by Jackolas, December 15, 2009, 07:00:32 am

Previous topic - Next topic

Jackolas

December 15, 2009, 07:00:32 am Last Edit: December 15, 2009, 08:03:45 am by Jackolas
I have a question (probably really simple to fix)

atm I'm working on a script and in the configure I have for example how much exp an actor needs to lose.
now in a script I have this part:
Spoiler: ShowHide
  def remove_exp
   if Jackolas_GameOver::LoseExp
     if Jackolas_GameOver::ExpAmount >=1
       for actor in $game_party.actors
         explose = Jackolas_GameOver::ExpAmount
       end
     else
       for actor in $game_party.actors
         explose = actor.exp * Jackolas_GameOver::ExpAmount
       end
     end
     for actor in $game_party.actors
       actor.exp -= explose
     end
   end
 end

if I fill in like 0.5 in the config it works like a dream. no errors and 50% is removed.
only problem is that he puts now 1 number behind the "." in the number, like 10.0 exp  (if you know what I mean)
my question is how can I round that up/down so its a whole number again?
or prevent it from happening.

(yes I know I still need to build in a safety check so it won't try to remove exp below 0)

Blizzard

Use .round or .to_i to turn it into an integer. I suggest .to_i even tough it just truncates the numbers behind the decimal separator. You can apply that at the very end "actor.exp = actor.exp.to_i"
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Jackolas

works like a charm
Thanks blizz

Problem solved and learned something new