Jump to content

Math


Recommended Posts

Posted

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?

Posted
  
5/5 -- Dividing 
  
5*5 -- multiplying 
  
5-5 -- substraction 
  
5+5 -- addition 
  
  
  

( Renamed from BeaTzZ to [PXG]Blue )

Looking for a Scripter that can make you free / Paid Scripts with a negotiable price?

Look no further!

add me on skype: phoenix_beatzz

My GitHub

  • Moderators
Posted
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) 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

And how is valc[5] defined? What does it contain? Also you can just multiply by 1.5 and -0.5 and you'd get the same result. :D

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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...