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 


List from small to large, filter (table.sort)[Solved]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Tue Mar 23, 2021 7:19 am    Post subject: List from small to large, filter (table.sort)[Solved] Reply with quote

Hello there.
An example code is found below.
How do I list the list below from smallest to largest?

Code:
local pn1=[[item_aaaaaaaaaaa
item_bbbbbbbbbbbbbbbbbbbbbbbb
item_ccccccccccccccccc
item_aaaaaaaaaaaaaa
item_bbbbbbbbbbbbbbbbbbbbbbbbbb
item_cccccccccccccccccccc
item_aaaaaaa
item_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
item_ccccccccccccccc
item_aaaaaaaaaaaaaaaaa
item_bbbbbbbbbbbbbbbbbbbbb
item_ccccccccccccccccc
item_aaaaaaaaaaaaaaaaaaaaa
item_bbbbbbbbbbbbbbbbbbbbbbbb
item_ccccccccccccccccccccccccccc
item_aaaaaaaaa]]


function filter()

local SL = createStringlist()
SL.Text=pn1

for i=0, strings_getCount(SL)-1 do
local item1 = SL[i]
local item2 = SL[i]:sub(1, 6)
--print(item2)
local itemLeng = # (item1)

   if item2=="item_a" then
    print(itemLeng.." - "..item1)
   end
 end
SL.destroy()
end

filter()


result;
Code:
16 - item_aaaaaaaaaaa
19 - item_aaaaaaaaaaaaaa
12 - item_aaaaaaa
22 - item_aaaaaaaaaaaaaaaaa
26 - item_aaaaaaaaaaaaaaaaaaaaa
14 - item_aaaaaaaaa


The list I want;
Code:
12 - item_aaaaaaa
14 - item_aaaaaaaaa
16 - item_aaaaaaaaaaa
19 - item_aaaaaaaaaaaaaa
22 - item_aaaaaaaaaaaaaaaaa
26 - item_aaaaaaaaaaaaaaaaaaaaa


Probably "table.sort" should be used.
However, it confuses me.
Is it possible to get a short sample?
-----------------------------------------------------------
-----------------------------------------------------------

[ EDIT ]

Thanks @Corroder.
I followed the traces you left.
Here's the simple sort method for those who need it.

Code:
function filter()
local SL = createStringlist()
SL.Text=pn1
UDF1.CEMemo2.Lines.Add("")
for i=0, strings_getCount(SL)-1 do
local item1 = SL[i]
local item2 = SL[i]:sub(1, 6)
local itemLeng = # (item1)
if item2=="item_a" then
UDF1.CEMemo2.Lines.Add(itemLeng.." - "..item1)
   end
 end
SL = nil
end

function GetTheTableList()
 local T = {}
 local SL=createStringlist()
 SL.Text=UDF1.CEMemo1.Lines.Text
 for i=0,strings_getCount(SL)-1 do
  T[i] = strings_getString(SL,i)
  --print("T - "..T[i])   -- Output
 end
 SL = nil
 return T
end

function SortByTable(sender)
 Tablesort = {}
 for x = 0, #sender do
  Tablesort[x] = sender[x]
 end
 table.sort(Tablesort)
 return Tablesort   --- retunr new table preserving old table
end

function UDF1_CEButton1Click(sender)
filter()
end

function UDF1_CEButton2Click(sender)
tbl2 = GetTheTableList()
Sort = SortByTable(tbl2)
for x = 0, #Sort do
--print(Sort[x])   
UDF1.CEMemo3.Lines.Add(Sort[x])
end
end
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