Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[Solved]How would I detect if one of the three values are the highest?

Asked by 9 years ago
a  = 10
b = 1
c = 5

If people voted and these were the results how would I figure out whats the highest?

2 answers

Log in to vote
3
Answered by 9 years ago

This is a more complex way, but would be able to work with multiple numbers, or variables. Which could all be set into a table. I know you didn't ask for this exactly but this might help fix the problem or help in the future.

local a = 10
local b = 1
local c = 5

local Dictionary = {"a", "b", "c", "d", "e", "f", "g", "h", "I", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}

function Compare(Args)
local HighestNumber = nil --The highestnumber out of the table
local Letter = nil --The letter that goes with the highestnumber like A,B,C, etc.
for I,v in pairs(Args) do --Grabs all of the variables from the table, and cycles until it's read through eah variable.
if HighestNumber == nil then
HighestNumber = v
Letter = Dictionary[I]
else
if v > HighestNumber then
HighestNumber = v
Letter = Dictionary[I]
end
end
end
end
Compare({a, b, c}) --{a,b,c} --A table, it stores the numbers from the variables a,b, and c.
0
Sorry about the capital I's, most of them are suppose to be lower cased. But my computer automatically capitalizeses I's. xImmortalChaos 565 — 9y
0
thx anyways rabidhalofan12345 55 — 9y
1
Np, hope you can understand that in some ways. Thought it would just be cool to show you how you can expand on that type of stuff. xImmortalChaos 565 — 9y
Ad
Log in to vote
1
Answered by
Hybric 271 Moderation Voter
9 years ago
a  = 10
b = 1
c = 5
if a > b and a > c then
print("a wins")
else
if b > a and b > c then
print("b wins")
else
if c > a and c > b then
print(" c wins")
end
wait()
end
wait()
end
0
Change the values around (a,b,c) to test out the script! Hybric 271 — 9y
2
Good idea, but recheck your code. :P There are 'if then end' statements in the each 'if then end' statements; consider changing to 'elseif' for the two inside the first. TheeDeathCaster 2368 — 9y
0
Also, post an explanation, not just code. Perci1 4988 — 9y

Answer this question