 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Thu Mar 30, 2017 9:48 am Post subject: Populating a ListView |
|
|
I have a different ListBox question, this time populating from a table. The data table looks like this, followed by my attempt to load the data into a table. Code: | trainer = {
Data = {
PlayerColor = {
[0] = 'Red';
[1] = 'Blue';
[2] = 'Tan';
[3] = 'Green';
[4] = 'Orange';
[5] = 'Purple';
[6] = 'Teal';
[7] = 'Pink';
[8] = 'No Color';
};--PlayerColor
Characters = {
[0] = 'Orrin';
[1] = 'Valeska';
[2] = 'Edric';
[3] = 'Sylvia';
[4] = 'Lord Haart';
[5] = 'Sorsha';
[6] = 'Christian';
[7] = 'Tyris';
...
[127] = 'Tiva';
[128] = "No One";
...
self.listview = createListView(self.form)
setProperty(self.listview, 'ViewStyle', 'vsReport')
setProperty(self.listview, 'RowSelect', 'True')
setProperty(self.listview, 'ReadOnly', 'True')
setProperty(self.listview, 'HideSelection', 'False')
self.listview.top = 190;
self.listview.width = 140;
self.listview.left = 100;
self.listview.height = 230;
self.listview_colum1 = self.listview.getColumns().add()
self.listview_colum2 = self.listview.getColumns().add()
self.listview_colum1.Width = 0;
self.listview_colum2.Width = 140;
self.listview_colum1.Caption = 'Index';
self.listview_colum2.Caption = 'Character';
i = self.Data.Characters[index] + 1;
for _,__table in pairs(self.Data.Characters[i]) do
local entry = self.listview.getItems().add();
entry.Caption = __table[1];
local subentry = entry.getSubItems().add(__table[2]);
end |
The table when opened gives the error:
Error:[string "--function FormShow(sender)..."]:896: attempt to perform arithmetic on field '?' (a nil value)
Since an "index" has not been defined, I can understand the error. If the i = self.Data.Characters[index] + 1; is deleted, I get this error:
Error:[string "--function FormShow(sender)..."]:896: bad argument #1 to 'pairs' (table expected, got nil)
What would be the proper code steps to load the data? Once the data is loaded and one of the characters is selected then I need to use this selection to load another ListView as shown in the attachment.
Description: |
|
Filesize: |
22.86 KB |
Viewed: |
15358 Time(s) |

|
|
|
Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Thu Mar 30, 2017 5:01 pm Post subject: |
|
|
After you deleted the instruction, what did you expect "i" to equal?
Of course this returned nil: trainer.Data.Characters[nil]
Your Characters table is a list of strings. Why are you trying to treat them like tables?
Code: | for _, name in pairs(trainer.Data.Characters) do
print(name)
end |
I can only assume you wanted:
Code: | for _, name in pairs(trainer.Data.Characters) do
local entry = self.listview.getItems().add()
entry.Caption = name
for _, color in pairs(trainer.Data.PlayerColor) do
local subentry = entry.getSubItems().add(color)
end
end |
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Thu Mar 30, 2017 5:47 pm Post subject: |
|
|
Zanzer wrote: | After you deleted the instruction, what did you expect "i" to equal?
Of course this returned nil: trainer.Data.Characters[nil]
Your Characters table is a list of strings. Why are you trying to treat them like tables?
Code: | for _, name in pairs(trainer.Data.Characters) do
print(name)
end |
I can only assume you wanted:
Code: | for _, name in pairs(trainer.Data.Characters) do
local entry = self.listview.getItems().add()
entry.Caption = name
for _, color in pairs(trainer.Data.PlayerColor) do
local subentry = entry.getSubItems().add(color)
end
end |
|
Almost but not what I was looking to achieve. The output is Red for however many lines
Code: | for _, name in pairs(self.Data.Characters) do
local entry = self.listview.getItems().add()
entry.Caption = name
for _, color in pairs(trainer.Data.Characters) do
local subentry = entry.getSubItems().add(name)
end
end |
Results in(see image), now if one of the names is selected, what is the syntax to use that name in the Lv, Exp ListView to the right? This is intended to be used to edit the experience of the selected character.
You asked why I'm treating them as a table, from a different CE table, same data structure as listed above, Of course I'm not using a RadioGroup to select the "name" as is the current case, however this look suspiciously like a data table {index, data}.
Code: | self.characters_rg.onClick = function (sender)
local index = strings_getString(sender.getItems(), sender.ItemIndex);
local i = nil;
i = self.Data.Characters[index] + 1;
if i then
heroname = index;
--print("The index selected is", self.Data.Characters[index]);
--print("The hero selected from index is ", index);
print("The hero name is ", heroname);
self.listview.clear();
for _,__table in pairs(self.Data.Stats[i]) do
local entry = self.listview.getItems().add();
entry.Caption = __table[1];
local subentry = entry.getSubItems().add(__table[2]);
end
end
if expvalue and goldvalue and heroname then
RecalculateAddresses()
end
end |
This set of data is from, just like the current example immediately after the names
Code: | Stats = { -- Exp and level
{{1,999};{2,1999};{3,3199};{4,4599};{5,6199};{6,7999};{7,9999};{8,12199};{9,14699};{10,17499};{11,20599};{12,24319};{13,28783};{14,34139};{15,40566};{16,48278};{17,57532};{18,68636};{19,81960};{20,97948};{21,117133};{22,140155};{23,167781};{24,200932};{25,240713};{26,288450};{27,345734};{28,414474};{29,496962};{30,595947};{31,714729};{32,857267};{33,1028312};{34,1233566};{35,1479870};{36,1775434};{37,2130110};{38,2555721};{39,3066454};{40,3679333};{41,4414787};{42,5297331};{43,6356383};{44,7627245};{45,9152279};{46,10982319};{47,13178367};{48,15813624};{49,18975932};{50,22770701};{51,27324423};{52,32788889};{53,39346248};{54,47215078};{55,56657674};{56,67988789};{57,81586127};{58,97902932};{59,117483098};{60,140979297};{61,169174735};{62,203009260};{63,243610690};{64,292332406};{65,350798465};{66,420957735};{67,505148859};{68,606178207};{69,727413424};{70,872895684};{71,1047474396};{72,1256968850};{73,1508362194};{74,1810034206}};--0
{{1,999};{2,1999};{3,3199};{4,4599};{5,6199};{6,7999};{7,9999};{8,12199};{9,14699};{10,17499};{11,20599};{12,24319};{13,28783};{14,34139};{15,40566};{16,48278};{17,57532};{18,68636};{19,81960};{20,97948};{21,117133};{22,140155};{23,167781};{24,200932};{25,240713};{26,288450};{27,345734};{28,414474};{29,496962};{30,595947};{31,714729};{32,857267};{33,1028312};{34,1233566};{35,1479870};{36,1775434};{37,2130110};{38,2555721};{39,3066454};{40,3679333};{41,4414787};{42,5297331};{43,6356383};{44,7627245};{45,9152279};{46,10982319};{47,13178367};{48,15813624};{49,18975932};{50,22770701};{51,27324423};{52,32788889};{53,39346248};{54,47215078};{55,56657674};{56,67988789};{57,81586127};{58,97902932};{59,117483098};{60,140979297};{61,169174735};{62,203009260};{63,243610690};{64,292332406};{65,350798465};{66,420957735};{67,505148859};{68,606178207};{69,727413424};{70,872895684};{71,1047474396};{72,1256968850};{73,1508362194};{74,1810034206}};--1
{{1,999};{2,1999};{3,3199};{4,4599};{5,6199};{6,7999};{7,9999};{8,12199};{9,14699};{10,17499};{11,20599};{12,24319};{13,28783};{14,34139};{15,40566};{16,48278};{17,57532};{18,68636};{19,81960};{20,97948};{21,117133};{22,140155};{23,167781};{24,200932};{25,240713};{26,288450};{27,345734};{28,414474};{29,496962};{30,595947};{31,714729};{32,857267};{33,1028312};{34,1233566};{35,1479870};{36,1775434};{37,2130110};{38,2555721};{39,3066454};{40,3679333};{41,4414787};{42,5297331};{43,6356383};{44,7627245};{45,9152279};{46,10982319};{47,13178367};{48,15813624};{49,18975932};{50,22770701};{51,27324423};{52,32788889};{53,39346248};{54,47215078};{55,56657674};{56,67988789};{57,81586127};{58,97902932};{59,117483098};{60,140979297};{61,169174735};{62,203009260};{63,243610690};{64,292332406};{65,350798465};{66,420957735};{67,505148859};{68,606178207};{69,727413424};{70,872895684};{71,1047474396};{72,1256968850};{73,1508362194};{74,1810034206}};--2
{{1,999};{2,1999};{3,3199};{4,4599};{5,6199};{6,7999};{7,9999};{8,12199};{9,14699};{10,17499};{11,20599};{12,24319};{13,28783};{14,34139};{15,40566};{16,48278};{17,57532};{18,68636};{19,81960};{20,97948};{21,117133};{22,140155};{23,167781};{24,200932};{25,240713};{26,288450};{27,345734};{28,414474};{29,496962};{30,595947};{31,714729};{32,857267};{33,1028312};{34,1233566};{35,1479870};{36,1775434};{37,2130110};{38,2555721};{39,3066454};{40,3679333};{41,4414787};{42,5297331};{43,6356383};{44,7627245};{45,9152279};{46,10982319};{47,13178367};{48,15813624};{49,18975932};{50,22770701};{51,27324423};{52,32788889};{53,39346248};{54,47215078};{55,56657674};{56,67988789};{57,81586127};{58,97902932};{59,117483098};{60,140979297};{61,169174735};{62,203009260};{63,243610690};{64,292332406};{65,350798465};{66,420957735};{67,505148859};{68,606178207};{69,727413424};{70,872895684};{71,1047474396};{72,1256968850};{73,1508362194};{74,1810034206}};--3
... |
I'm not arguing as I am in a position of weakness, just trying to code some events.
Thanks
Description: |
|
Filesize: |
26.43 KB |
Viewed: |
15304 Time(s) |

|
|
|
Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Thu Mar 30, 2017 7:22 pm Post subject: |
|
|
That code is correctly indexing the Stats variable, which is a table. Code: | for _,__table in pairs(self.Data.Stats[i]) do |
You tried to index the Characters variable, which is a string. Code: | for _,__table in pairs(self.Data.Characters[i]) do |
That data looks more like the level number and the maximum experience.
Level 1 takes you to 999 experience. Level 2: 1999. Level 3: 3199.
And it's the same list over and over again, which seems... useless.
Your third box would always be populated with the same data, so just populate it once, during startup.
If there are indeed other leveling increments, you could make your table smaller by reusing the distinct tables. Code: | local DefaultStats = {{1,999};{2,1999};{3,3199};...}
local OtherStats = {{1,10};{2,20};{3,30};...}
Stats = { DefaultStats; DefaultStats; DefaultStats; OtherStats; DefaultStats; } |
As far as selecting the right index, you may be able to get away with: Code: | local i = sender.ItemIndex + 1
self.listview.clear();
for _,__table in pairs(self.Data.Stats[i]) do
local entry = self.listview.getItems().add();
entry.Caption = __table[1];
local subentry = entry.getSubItems().add(__table[2]);
end |
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Thu Mar 30, 2017 8:33 pm Post subject: |
|
|
Zanzer wrote: | That code is correctly indexing the Stats variable, which is a table. Code: | for _,__table in pairs(self.Data.Stats[i]) do |
You tried to index the Characters variable, which is a string. Code: | for _,__table in pairs(self.Data.Characters[i]) do |
That data looks more like the level number and the maximum experience.
Level 1 takes you to 999 experience. Level 2: 1999. Level 3: 3199.
And it's the same list over and over again, which seems... useless.
|
For this case I would agree, but it is a specific case the general case would have different numbers. So useless now, not necessarily for all time. Quote: |
Your third box would always be populated with the same data, so just populate it once, during startup. |
Again for this case the data would be the same but not as a general rule. Quote: |
If there are indeed other leveling increments, you could make your table smaller by reusing the distinct tables. Code: | local DefaultStats = {{1,999};{2,1999};{3,3199};...}
local OtherStats = {{1,10};{2,20};{3,30};...}
Stats = { DefaultStats; DefaultStats; DefaultStats; OtherStats; DefaultStats; } |
|
That seems doable. Quote: |
As far as selecting the right index, you may be able to get away with: Code: | local i = sender.ItemIndex + 1
self.listview.clear();
for _,__table in pairs(self.Data.Stats[i]) do
local entry = self.listview.getItems().add();
entry.Caption = __table[1];
local subentry = entry.getSubItems().add(__table[2]);
end |
|
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Fri Mar 31, 2017 1:24 pm Post subject: |
|
|
bknight2602 wrote: | Zanzer wrote: | ...
As far as selecting the right index, you may be able to get away with: Code: | local i = sender.ItemIndex + 1
self.listview.clear();
for _,__table in pairs(self.Data.Stats[i]) do
local entry = self.listview.getItems().add();
entry.Caption = __table[1];
local subentry = entry.getSubItems().add(__table[2]);
end |
|
| Actually I was looking for whatever control/item that could be derived from selecting the Character Listview, setting heroname = to that item.
|
|
Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sat Apr 01, 2017 7:52 am Post subject: |
|
|
Code: | local i = sender.ItemIndex
heroname = trainer.Data.Characters[i] |
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Sat Apr 01, 2017 10:04 am Post subject: |
|
|
Zanzer wrote: | Code: | local i = sender.ItemIndex
heroname = trainer.Data.Characters[i] |
|
That results in
(Error executing this tables lua script: Undefined lua error)-->as a pop-up window
error attempt to index global 'sender' (a nil value)-->in the debug window
at table load.
EDIT:
As a side note, although i isn't set to anything, that I can find, a print statement of heroname results in Valeska ItemIndex 1 after the sender line is commented out.
|
|
Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sat Apr 01, 2017 1:23 pm Post subject: |
|
|
That line needed to be in the list's OnClick event.
If heroname is populating, it sounds like other code already is doing this functionality.
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Sun Apr 02, 2017 4:57 pm Post subject: |
|
|
Excellent. Good eye and/or experience.
Thanks
|
|
Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 582
|
Posted: Sat Jul 08, 2017 7:17 pm Post subject: |
|
|
Different game, different problem: listview loads but not in order of entries.
Code: | trainer = {
Data = {
Characters = {
[0] = 'Hero';
[1] = 'Hero son';
[2] = 'Hero daughter';
[3] = 'Bianca';
[4] = 'Young Bianca';
[5] = 'Sancho';
[6] = 'Pipin';
[7] = 'Flora';
[8] = 'Papas';
[9] = 'Henry';
[10] = 'Bella';
[128] = 'Baby phanter';
[129] = 'Kill phanter';
[130] = 'Slime';
[131] = 'Drakee';
[132] = 'Magician';
[133] = 'Healer';
[134] = 'Dancing needle';
[135] = 'Slime knight';
[136] = 'Brownie';
[137] = 'Bomb baby';
[138] = 'Hork';
[139] = 'Yeta';
[140] = 'Dragon pup';
[141] = 'Kukkle';
[142] = 'Big eye';
[143] = 'Metal babble';
[144] = 'Puppet man';
[145] = 'Wyvern';
[146] = 'Bomb crag';
[147] = 'Dancing jewel';
[148] = 'Curer';
[149] = 'King slime';
[150] = 'Mad dragon';
[151] = 'Minidemon';
[152] = 'Messala';
[153] = 'Orc king';
[154] = 'Leaonar';
[155] = 'Eliminator';
[156] = 'Golem';
[157] = 'Centaurus';
[158] = 'King healer';
[159] = 'Soldier bull';
[160] = 'Farewell crag';
[161] = 'Eigerhorn';
[162] = 'Blizzard hawk';
[163] = 'Springer';
[164] = 'Great dragon';
[165] = 'Attack bot';
[166] = 'Lionex';
[167] = 'Gigantes';
[168] = 'Hell battler';
[169] = 'Neileus';
};--Characters
};--Data
};--Trainer
function trainer:start()
self.form = createForm(false); -- self = trainer since it's a function inside of a table...
setProperty(self.form , "BiDiMode", "bdLeftToRight");
self.form.Caption = 'Cheat Panel';
self.form.Width = 400;
self.form.Height = 400;
self.form.Left = 900;
self.form.Top =5;
self.listview2 = createListView(self.form)--Character Names
setProperty(self.listview2, 'ViewStyle', 'vsReport')
setProperty(self.listview2, 'RowSelect', 'True')
setProperty(self.listview2, 'ReadOnly', 'True')
setProperty(self.listview2, 'HideSelection', 'False')
self.listview2.top = 110;
self.listview2.width = 230;
self.listview2.left = 5;
self.listview2.height = 280;
self.listview2_colum1 = self.listview2.getColumns().add()
self.listview2_colum1.Width = 220;
self.listview2_colum1.Caption = 'Name';
for __, name in pairs(self.Data.Characters) do--self.Data.Characters[i]
local entry = self.listview2.getItems().add();
entry.Caption = name--__table[1];
end;
self.listview2.onClick = function(sender)
local i = sender.ItemIndex
print(i)
end
trainer:start(); |
The listview loads properly from 0-10 then skips to 20 loads in order through the end, then adds 11-19 at the end. When an item is selected the index is not as intended. 1-10 are correct the next is 11 even though the index should be 139. At the end of the list, the last item is 52, the number of entries minus one.
The numbers for each name will be keyed to a table value, so it would be good to retain them, if possible.
What am I missing? How should the code be corrected to produce the desired results?
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 467
Joined: 09 May 2003 Posts: 25705 Location: The netherlands
|
Posted: Sun Jul 09, 2017 12:16 am Post subject: |
|
|
try ipairs instead of pairs
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
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
|
|