|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Drivium Advanced Cheater Reputation: 0
Joined: 16 Apr 2013 Posts: 97
|
Posted: Wed Jul 03, 2019 10:17 am Post subject: Need little lua script to alphabetize my drop down lists |
|
|
I've got several drop down lists (hundreds) and when I initially designed it, I alphabetized the items by the string name as opposed to the friendly name. It's making finding the drop down item I want quite difficult. Hoping this can be solved with LUA.
Would just be a 1 time use thing... It would run through my drop down lists and alphabetize each. Then I'll save my table and be good to go.
Hoping it can alphabetize by the friendly names as opposed to the string.
In other words, alphabetize by the items on the right side of :
Weapon_Bow_015:Golden Bow
Weapon_Bow_016:Swallow Bow
Weapon_Bow_017:Falcon Bow
Weapon_Bow_023:Ancient Bow
Weapon_Bow_026:Mighty Lynel Bow
Weapon_Bow_027:Dragon Bone Boko Bow
Weapon_Sword_048:Meteor Rod
Weapon_Sword_049:Blizzard Rod
Weapon_Sword_050:Thunderstorm Rod
Weapon_Sword_051:Boomerang
Thanks in advance!
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Thu Jul 04, 2019 2:36 pm Post subject: |
|
|
I played around with this Code: | print('\n\n\n\n\n') -- make new output obvious when testing
-- input in one new line separated string
local str = [[Weapon_Sword_048:Meteor Rod
Weapon_Sword_049:Blizzard Rod
Armor_Helm_999:Some Test Armor
Weapon_Sword_050:Thunderstorm Rod
Weapon_Sword_051:Boomerang
Weapon_Bow_015:Golden Bow
Weapon_Bow_016:Swallow Bow
Weapon_Bow_017:Falcon Bow
Armor_Plate_999:Some Other Armor
Armor_Plate_999:Some Heavier Armor
Weapon_Bow_023:Ancient Bow
Weapon_Bow_026:Mighty Lynel Bow
Weapon_Bow_027:Dragon Bone Boko Bow]]
local list = {} -- for sorting
-- split lines, [^...]=not in this set, \n=new line, +=1 or more
for line in str:gmatch('[^\n]+') do
-- split info d=digits, (...)=separate group/capture
for class,type,id,name in line:gmatch('([^_]+)_([^_]+)_(%d+):([^\n]+)') do
-- put into table for sorting later
table.insert(list, {line, class, type, name, id})
end
end
table.sort(list, function(a, b)
if a[2] ~= b[2] then return a[2] < b[2] -- weapon/armor
elseif a[3] ~= b[3] then return a[3] < b[3] -- bow/sword
elseif a[4] ~= b[4] then return a[4] < b[4] -- name
else return a[5] < b[5] end -- number
end)
-- print sorted list, alternatively clear and add in order to something else
for k,v in ipairs(list) do
-- %-40s = print string, left aligned, with at least 40 characters
print(('%-40s %s %s "%s"'):format(v[1],v[2], v[3], v[4]))
end |
maybe you can find something useful in it.
_________________
|
|
Back to top |
|
|
atom0s Moderator Reputation: 199
Joined: 25 Jan 2006 Posts: 8518 Location: 127.0.0.1
|
Posted: Thu Jul 04, 2019 7:32 pm Post subject: |
|
|
You can split the strings as they are being sorted and compare the ending part like this:
Code: |
local items =
{
'Weapon_Bow_015:Golden Bow',
'Weapon_Bow_016:Swallow Bow',
'Weapon_Bow_017:Falcon Bow',
'Weapon_Bow_023:Ancient Bow',
'Weapon_Bow_026:Mighty Lynel Bow',
'Weapon_Bow_027:Dragon Bone Boko Bow',
'Weapon_Sword_048:Meteor Rod',
'Weapon_Sword_049:Blizzard Rod',
'Weapon_Sword_050:Thunderstorm Rod',
'Weapon_Sword_051:Boomerang'
};
local function split(str, sep)
local sep = sep or ':';
local ret = {};
str:gsub(string.format('([^%s]+)', sep), function (s)
ret[#ret + 1] = s;
end);
return ret;
end
table.sort(items, function(a, b)
local p1 = split(a, ':');
local p2 = split(b, ':');
return p1[2] < p2[2];
end);
for k, v in pairs(items) do
print(v);
end
|
Which will result in:
Code: |
Weapon_Bow_023:Ancient Bow
Weapon_Sword_049:Blizzard Rod
Weapon_Sword_051:Boomerang
Weapon_Bow_027:Dragon Bone Boko Bow
Weapon_Bow_017:Falcon Bow
Weapon_Bow_015:Golden Bow
Weapon_Sword_048:Meteor Rod
Weapon_Bow_026:Mighty Lynel Bow
Weapon_Bow_016:Swallow Bow
Weapon_Sword_050:Thunderstorm Rod
|
_________________
- Retired. |
|
Back to top |
|
|
Drivium Advanced Cheater Reputation: 0
Joined: 16 Apr 2013 Posts: 97
|
Posted: Fri Jul 05, 2019 11:00 am Post subject: |
|
|
Thank you both for the solutions! This will save me so much manual work!
|
|
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
|
|