|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
azamalvi Cheater Reputation: 0
Joined: 16 Aug 2013 Posts: 26
|
Posted: Sat Sep 24, 2016 1:25 am Post subject: Sort Arry after using velue between |
|
|
I am first searching values then I want to print those values. And those values must b sorted. I using table.sort but not getting sorted result. Below is my code
Code: | local memscan = createMemScan()
local foundlist = createFoundList(memscan)
memscan.firstScan(
soValueBetween, vtDword, rtRounded,
1, 99, 0, 0xffffffffffffffff, "+W-C",
fsmAligned, "4", false, false, false, false)
memscan.waitTillDone()
foundlist.initialize()
local values = {}
local value = foundlist.Value
for i = 0, foundlist.Count - 1 do
values[value[i]] = true
end
foundlist.destroy()
memscan.destroy()
table.sort(values)
for i in pairs(values) do
print(i)
end |
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 941
|
Posted: Sat Sep 24, 2016 6:55 am Post subject: |
|
|
Lua table can be used as hash map or ordered linear array depending on how the operation see the table key.
As a hash map, operation like pairs/next in for statement will see all keys, but its order in for loop is unorder.
As an ordered liner array, operation like ipairs/sort, '#' for getting array length, can only see from numeric/integral key 1 to consecutive existed integer 'number' type keys.
For example, a literal Lua table with explicit key-value pairs
Code: |
local t = {
stringKey = 'non-numeric key cannot be seen in array',
[0] = 0,
[1] = 1,
[2] = 2,
[3] = 3,
[4.5] = 4.5,
[10] = 10,
}
print('pairs loop in all keys, unordered')
for k,v in pairs(t) do
print(k,' = ',v)
end
print('')
print('ipairs loop in consecutive integer key from 1, ordered')
for i,v in ipairs(t) do
print(i,' = ',v)
end |
The ipairs stop at key 3 because the next consecutive integer key 4 is not existed in the table.
So the table.sort is not working on values since its key is all 'string' type.
To collect the foundlist.Value as array , try following, but before that note that the element content of Value is of 'string' type, '9' > '10' (string type compare) vs 9 < 10 (number type compare), so if the Value is numeric in nature, it should convert to appropriate type 1st, the conversion may depend on if the value is 'show as hex' during scan. The following assume the value is non-hex numbers format.
Code: |
for i = 0, foundlist.Count - 1 do
values[i+1] = tonumber(foundlist.Value[i]) -- 1st key is (0+1) = 1
end
|
bye~ _________________
- Retarded. |
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sat Sep 24, 2016 8:28 am Post subject: |
|
|
Code: | local sorted = {}
for i in pairs(values) do
sorted[#sorted+1] = i
end
table.sort(sorted)
for i, v in ipairs(sorted) do
print(v)
end |
|
|
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
|
|