View previous topic :: View next topic |
Author |
Message |
Filipe_Br Master Cheater Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Sat Aug 20, 2016 12:07 pm Post subject: compare with Table values |
|
|
The script below is some of what I want to do.
How can I find out if the variable "value" is less than the table values "Test_Table"?
Code: |
Test_Table = {31, 60, 80 , 10}
Value = 7
print("The value is lower than the values of Test Table? " .. That part I do not know :( )
|
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Sat Aug 20, 2016 1:57 pm Post subject: |
|
|
I can't test it here, but have you tried math.min(unpack(Test_Table))
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Filipe_Br Master Cheater Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Sat Aug 20, 2016 3:33 pm Post subject: |
|
|
One more question. I did the script below and it returns 10 that is correct, 10 is the 4 item in this table. What returns which is the table item with the lowest value?
Code: |
Test_Table = {31, 60, 80, 10}
print("Lower value: " .. math.min(unpack(Test_Table)) .. " It's the ".. Still do not know '-' .. " table item") |
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Sat Aug 20, 2016 3:40 pm Post subject: |
|
|
use a for loop
Code: |
minindex=1
for i=2 to #Test_Table do
if Test_Table[i]<Test_Table[minindex] then
minindex=i
end
end
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Filipe_Br Master Cheater Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Sat Aug 20, 2016 5:09 pm Post subject: |
|
|
For my first problem solve with this script.
Code: |
Test_Table = {31, 60, 50 , 10}
Value= 7
for a,b in pairs(Test_Table) do
if Value < math.min(unpack(Test_Table)) then
result='Yes'
else
result='No'
end
end
print("The value is lower than the values of Test Table? "..result) |
And for my second problem it works well.
Code: |
Test_Table = {31, 60, 50 , 10}
for a,b in pairs(Test_Table) do
if math.min(unpack(Test_Table)) == b then
result=a
end
end
print("Lower value: " .. math.min(unpack(Test_Table)) .. " It's the ".. result .. " table item") |
|
|
Back to top |
|
|
|