Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


table.sort result as if else bolean expression

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
icsmoke+
Cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 29

PostPosted: Thu Jun 02, 2022 6:01 am    Post subject: table.sort result as if else bolean expression Reply with quote

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
View user's profile Send private message
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Thu Jun 02, 2022 6:25 am    Post subject: Re: table.sort result as if else bolean expression Reply with quote

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
View user's profile Send private message
Skyrimfus
Cheater
Reputation: 1

Joined: 17 Mar 2016
Posts: 43

PostPosted: Thu Jun 02, 2022 9:16 am    Post subject: Reply with quote

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
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1520

PostPosted: Thu Jun 02, 2022 10:36 am    Post subject: Reply with quote

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

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu Jun 02, 2022 8:35 pm    Post subject: This post has 1 review(s) Reply with quote

My turn:

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 k,v in pairs(tab) do
 if tab[k] == tes then print(v.." true") else print(v.." false") end
end

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
icsmoke+
Cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 29

PostPosted: Fri Jun 03, 2022 7:09 pm    Post subject: Reply with quote

you guys r awesome ty in advanced
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites