StefanAlmighty Posted October 26, 2015 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?
[PXG]Blue Posted October 26, 2015 Posted October 26, 2015 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 IIYAMA Posted October 26, 2015 Moderators 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) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Dealman Posted October 26, 2015 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. 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.
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