767 posts
Posted 02 November 2013 - 08:03 AM
hello..
I just wanted to find the biggest number in 5 different variables like this:
m = 1
t = 7
s = 3
y = 22
then the script has to choose the y, because its the biggest number…
I totally forgot how to do this thing, therefore i ask here…
Thanks in advance
48 posts
Location
France
Posted 02 November 2013 - 08:06 AM
math.max(m,t,s,y)
758 posts
Location
Budapest, Hungary
Posted 02 November 2013 - 08:06 AM
Man…
print(math.max(m, t, s, y))
EDIT: I hate when the forum can't keep up with the ninjas :D/>
48 posts
Location
France
Posted 02 November 2013 - 08:08 AM
Pipped at the post! :ph34r:/>
767 posts
Posted 02 November 2013 - 08:16 AM
Okay.. Thanks :)/>
767 posts
Posted 06 November 2013 - 09:52 AM
Just have to ask a bit different( yes the previous posts worked correct and thats good), but:
Is it possible to see the math.max code in the math api( which doesnt exist) ?
Thanks
7508 posts
Location
Australia
Posted 06 November 2013 - 10:47 AM
Is it possible to see the math.max code in the math api( which doesnt exist) ?
But it does exist…. but this is how it'd be done
function maxNumber(...)
--# get all the args
local args = {...}
-- make sure there are some args
if #args == 0 then
error("Missing arguments", 2)
end
-- now to the logic
local max = args[1] -- we set it to the first element in the array instead of a number such as 0, just incase all the arguments are negative
for i,v in pairs(args) do
-- just some validation, making sure its a number
if type(v) ~= "number" then
error("Arg #"..i.." is not a number", 2)
end
-- is it the biggest?
if v > max then
-- yes it was
max = v
end
end
return max
end