 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
icsmoke+ Cheater
Reputation: 0
Joined: 31 Aug 2020 Posts: 29
|
Posted: Thu Jun 02, 2022 6:01 am Post subject: table.sort result as if else bolean expression |
|
|
helo there as a subject says, is it possible to use table.sort result as if else statement
heres the code
Code: |
tes = 1
local tab = {1,2,3,5,4,6}
local function compare( a, b )
return a > b
end
table.sort( tab, compare )
for i=1, 9 do
if tab[i] == tes then print(true) else print(false) end
end
|
it gives nothing but blank result the code should be true in the final result
thanks in advance
|
|
Back to top |
|
 |
Frouk Grandmaster Cheater
Reputation: 5
Joined: 22 Jun 2021 Posts: 510
|
Posted: Thu Jun 02, 2022 6:25 am Post subject: Re: table.sort result as if else bolean expression |
|
|
icsmoke+ wrote: | helo there as a subject says, is it possible to use table.sort result as if else statement
heres the code
Code: |
tes = 1
local tab = {1,2,3,5,4,6}
local function compare( a, b )
return a > b
end
table.sort( tab, compare )
for i=1, 9 do
if tab[i] == tes then print(true) else print(false) end
end
|
it gives nothing but blank result the code should be true in the final result
thanks in advance |
you are trying to print boolean type
instead use print("true") or print("false")
print uses string type, it doesn't recognize the bool
|
|
Back to top |
|
 |
Skyrimfus Cheater
Reputation: 1
Joined: 17 Mar 2016 Posts: 43
|
Posted: Thu Jun 02, 2022 9:16 am Post subject: |
|
|
Code: |
arr1 = {8,2,7,1,2,9,2}
arr2 = {8,2,7,1,2,9,2}
table.sort(arr1,function(a,b)--sort lowest to highest
return a<b
end)
table.sort(arr2,function(a,b)--sort highest to lowest
return b<a
end)
return arr1,arr2--print table elements and values |
|
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1520
|
Posted: Thu Jun 02, 2022 10:36 am Post subject: |
|
|
Code: | tes = 4
local tab = {7,1,2,8,3,5,4,9,6}
table.sort(tab) --, compare )
for i=1, #tab do
if tab[i] == tes then print(tab[i],"true") else print(tab[i],"false") end
end |
or
Code: | tes = 4
local tab = {7,1,2,8,3,5,4,9,6}
table.sort(tab) --, compare )
for i,k in pairs(tab) do
if k == tes then print(k,"true") else print(k) end
end |
_________________
|
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
|
Back to top |
|
 |
icsmoke+ Cheater
Reputation: 0
Joined: 31 Aug 2020 Posts: 29
|
Posted: Fri Jun 03, 2022 7:09 pm Post subject: |
|
|
you guys r awesome ty in advanced
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|