Jump to content

Math


Recommended Posts

Is there a math function for adding, subtracting & dividing?

  
local upperbound = valc[5]/2+valc[5] -- halves and adds on to original 
local lowerbound = valc[5]/2-valc[5] -- halves and subtracts from original 
  

This, for me gives off a lot of random numbers. In my scenario, it loops through a table.

  
for indexc, valc in ipairs (data) do 
    local upperbound = valc[5]/2+valc[5] -- halves and adds on to original 
    local lowerbound = valc[5]/2-valc[5] -- halves and removes from original 
    valc[6] = math.random(lowerbound, upperbound) 
end 
  

But when I load the GUI in-game, the numbers are completely random. They range from like -300 to 600 and they shouldn't. It seems to be an issue with the sum?

Link to comment
  • Moderators
But when I load the GUI in-game, the numbers are completely random. They range from like -300 to 600 and they shouldn't. It seems to be an issue with the sum?

Round your values: down, up or both.

math.random require an integer value and not a float value.

int: 1 
float: 1.11111111111111111111111111111 

Down

local upperbound = math.floor(upperbound) 
local lowerbound = math.floor(lowerbound) 

Up

local upperbound = math.ceil(upperbound) 
local lowerbound = math.ceil(lowerbound) 

Both

local upperbound = math.floor(upperbound+0.5) 
local lowerbound = math.floor(lowerbound+0.5) 

Link to comment

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
  • Recently Browsing   0 members

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