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 


Correct sybtax for loading table values

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

Joined: 08 Oct 2012
Posts: 586

PostPosted: Wed Jan 29, 2014 7:16 pm    Post subject: Correct sybtax for loading table values Reply with quote

DaSpammer has graciously coded a trainer for me, and I am attempting to apply the trainer to other games. Here are parts of the code to identify what I have and what I'm looking at doing.
Code:

trainer =    {
            Data =    {
                        Characters =    {
                                          [0] = "Mariah-Mage"; -- Table auto selects characters based alphabet order... so we will append the characters to the groupbox using value index.
                                          [1] = "Iolo-Bard";
                                          [2] = "Geoff-Fighter";
                                          [3] = "Jaana-Druid";
                                          [4] = "Julius-Tinker";
                                          [5] = "Dupre-Paladin";
                                          [6] = "Shamino-Ranger";
                                          [7] = "Katrina-Shepard";
                                          [8] = "No One";

                                          ["Mariah-Mage"] = 0; -- Index of radiogroup
                                          ["Iolo-Bard"] = 1;
                                          ["Geoff-Fighter"] = 2;
                                          ["Jaana-Druid"] = 3;
                                          ["Julius-Tinker"] = 4;
                                          ["Dupre-Paladin"] = 5;
                                          ["Shamino-Ranger"] = 6;
                                          ["Katrina-Shepard"] = 7;
                                          ["No One"] = 8;
                                       };
                        Stats =   { -- Exp and level, need to try only one line as all the stats are equal
                                    {{1,99};{2,199};{3,399};{4,799};{5,1599};{6,3199};{7,6399};};
                                    {{1,99};{2,199};{3,399};{4,799};{5,1599};{6,3199};{7,6399};};
                                    {{1,99};{2,199};{3,399};{4,799};{5,1599};{6,3199};{7,6399};};
                                    {{1,99};{2,199};{3,399};{4,799};{5,1599};{6,3199};{7,6399};};
                                    {{1,99};{2,199};{3,399};{4,799};{5,1599};{6,3199};{7,6399};};
                                    {{1,99};{2,199};{3,399};{4,799};{5,1599};{6,3199};{7,6399};};
                                    {{1,99};{2,199};{3,399};{4,799};{5,1599};{6,3199};{7,6399};};
                                    {{1,99};{2,199};{3,399};{4,799};{5,1599};{6,3199};{7,6399};};
                                    {};
                                 };
                        goldoffset = {--goldoffset to be used in Recalculation function
                                        {0x92};
                                        {0x94};
                                        {0x96};
                                        {0x98};
                                        {0x9A};
                                        {0x9C};
                                        {0x9E};
                                        {0xA0};
                                        {};
                                     };
                      };
             };
function trainer:start()

...

...
   self.characters_rg = createRadioGroup(self.form);
   self.characters_rg.Caption = "Hero";
   self.characters_rg.height = 190;
   self.characters_rg.width = 130;
   self.characters_rg.top = 165;
   self.characters_rg.left = 5;
   for character,_ in pairs(self.Data.Characters) do
      if tonumber(character) then
         self.characters_rg.getItems().add(_);
      end
   end
   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;
                                       if heroname == "No One" then
                                          heroname = nil;
                                       else
                                       end;
                                       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;

Up to here is what DaSpammer coded and works without errors.
The following piece of code is mine trying to obtain the goldoffset from the goldoffset table.
Code:
 
                                       for _table in(self.Data.goldoffset[i]) do
                                          local goldoffset = self.Data.getItems()
                                          goldoffset.Caption = _table[0];
                                          goldoffset = self.Data.goldoffset[i];
                                       end;
                                    end;
                                 end;
...

...
   self.form.show();
   end;
trainer:start();



When I select a button on the radio group the level and experience is loaded into a list view correctly, as stated above.
But I get an error message "Error:[string "--..."]:454: attempt to call a table value". Yes I am trying to load a table value but I don't have the correct syntax.

So what would the correct syntax be to load the table value and then set it to a variable goldoffset that will be used in another function?
Back to top
View user's profile Send private message Yahoo Messenger
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Thu Jan 30, 2014 12:07 am    Post subject: Reply with quote

This
Quote:
for _table in(self.Data.goldoffset[i]) do
local goldoffset = self.Data.getItems()
goldoffset.Caption = _table[0];
goldoffset = self.Data.goldoffset[i];
end;
end;
end;


To

Quote:
for _table in(self.Data.goldoffset[i]) do
local goldoffset = self.listview.getItems().add();
goldoffset.Caption = _table[0];
goldoffset = self.Data.goldoffset[i];
end;
end;
end;

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Thu Jan 30, 2014 9:11 am    Post subject: Reply with quote

With .Data.goldoffset as in the previous post, I changed the code with your suggestions.
Code:
                                       for _table in(self.Data.goldoffset[i]) do
                                        local goldoffset = self.listview.getItems().add();
                                        goldoffset.Caption = _table[0];
                                        goldoffset = self.Data.goldoffset[i];
                                        print("The gold offset (goldoffset) is ", goldoffset);
                                       end;


Received the continued error message:
Error:[string "--..."]:454: attempt to call a table value

In fact I commented out all lines within the for statement:
Code:
                                       for _table in(self.Data.goldoffset[i]) do
                                        --local goldoffset = self.listview.getItems().add();
                                        --goldoffset.Caption = _table[0];
                                        --goldoffset = self.Data.goldoffset[i];
                                          --print("The gold offset (goldoffset) is ", goldoffset);
                                       end;


I continue to get the same error message.

Secondly, why have the statement ?
.Data.goldoffset has no direct relationship with .Data.Stats other than data relating to the hero selected by the button pushed in the radio group.
Code:
local goldoffset = self.listview.getItems().add();
Back to top
View user's profile Send private message Yahoo Messenger
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Thu Jan 30, 2014 12:49 pm    Post subject: Reply with quote

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;
                                       if heroname == "No One" then
                                          heroname = nil;
                                       else
                                       end;
                                       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; 
                                       self.listview.getItems().add().Caption = self.Data.goldoffset[1][1]; -- Adds entry with the caption of the offset tot he listview
                                       goldoffset = self.Data.goldoffset[1][1];  -- this is the gold offset
                                    end;
                                 end;

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Thu Jan 30, 2014 2:35 pm    Post subject: Reply with quote

DaSpamer wrote:
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;
                                       if heroname == "No One" then
                                          heroname = nil;
                                       else
                                       end;
                                       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; 
                                       self.listview.getItems().add().Caption = self.Data.goldoffset[1][1]; -- Adds entry with the caption of the offset tot he listview
                                       goldoffset = self.Data.goldoffset[1][1];  -- this is the gold offset
                                    end;
                                 end;

You probably missed type but [1][1] should be [i][1] and that works, however as you indicated another item is added to the list view. Is there a command to make just that last entry in the list view invisible. It looks kind of out of place in the list view.

EDIT: I commented out
Code:
self.listview.getItems().add().Caption = self.Data.goldoffset[1][1];


The code line you suggested still works and the entry isn't in the list view.
Thanks
Back to top
View user's profile Send private message Yahoo Messenger
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