StefanAlmighty Posted October 26, 2015 Share Posted October 26, 2015 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
[PXG]Blue Posted October 26, 2015 Share Posted October 26, 2015 5/5 -- Dividing 5*5 -- multiplying 5-5 -- substraction 5+5 -- addition Link to comment
Moderators IIYAMA Posted October 26, 2015 Moderators Share Posted October 26, 2015 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
Dealman Posted October 26, 2015 Share Posted October 26, 2015 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now