Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What do i use to determine which four different int values are higher?

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.

3 answers

✓ Accepted answer

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.

All the math functions

2 comments

0

You can just replace the numbers 1-9 with how many numbers and whatever numbers you want.

2

Your answer is underrated

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.

4 comments

0

i quite get it but not fully enough, but thank you! ill use this for knowledge in the long run.

1

With all due respect my godly lad, giving fully working code and not even explaining it is going to help him now but he can't learn from this.

0

The reason I recommend this way is from math.max and Virality’s way is that it returns the actual IntValue. The other two answers are only returning the highest number but I don’t see what you can do with just a number.

1

You can do lots of stuff, like math

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

6 comments

0

My god you're right.. why i have never think about this...i did a different method still works but i rather use this so its more computing power friendly thank you!

0

Np

0

-1 for reinventing math.max

0

programmerHere, this forum isn't for you man, this isn't a forum to shame others on their mistakes, it's about learning and creating a positive community.

0

Bad answer. -1.

0

I'm here to correct mistake bro

This discussion is preserved as it was. New answers, comments, and votes are closed.