What do i use to determine which four different int values are higher? and choose that value?
i tried doing for loops i just can't wraped my head around.
I'm no rocket scientist, but I'm pretty sure you can just use math.max for this sort of thing.
local highest = math.max(1,2,3,4,5,6,7,8,9) --//You can put whatever numbers you want in there. print(highest) --//Will output 9
You can also put the numbers inside of a table, and using the unpack function can unload them into the function like this.
local numbers = {1,2,3,4,5,6,7,8,9} local highest = math.max(unpack(numbers)) --//Is the same as the code from before, but this time we're taking all the values from the table and unpacking them into the math.max function. print(highest) --//Still outputs 9
Not sure if I'm reading the question wrong or not judging from the above answers, but the math.max function can certainly get the largest number from a group of numbers. Conversely there is the math.min function, which does the same thing but returns the smallest number.
This is quite simple.
local function SortIntValues(folder) local intValues = {} for i,v in pairs(folder:GetChildren()) do table.insert(intValues, v) end table.sort(intValues, function(a,b) return a.Value > b.Value end) return intValues[1] end local HighestIntValue = SortIntValues(folderWithIntValues) — This is the highest int value.
I'm kind of tired right now so if there is a predefined method for this somebody tell me, but here is a function you can use:
local one = 1 local two = 2 local three = 3 local four = 4 local values = { one, two, three, four, } function getHighest(table) highest = 0 for i,v in pairs(table) do if v > highest then highest = v end end return highest end