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 


Data table extraction and use
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bknight2602
Master Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 363

PostPosted: Fri Apr 07, 2017 6:15 pm    Post subject: Data table extraction and use Reply with quote

I'm attempting to use the table names for use elsewhere in the code.
Code:
trainer =    {
            Data =    {
                        GF =      {
                                          [0] = "name1";
                                          [1] = "name2";
                                          [2] = "name3";
                                          [3] = "nam4";
                                          [4] = "name5";
                                          [5] = "name6";
                                          [6] = "name7";
                                          [7] = "name8";
                                          [8] = "No One";
                                  };
                     };
            };
al = getAddressList()
for y = 0, 8 do
Name[y] = trainer.data.GF
print(Name[y])
end

The forum is giving me error messages, so all the names have been changed to get by the forum message
Sorry, but because xxxx is an online game you are not allowed to talk about it. If you bought it fuck you for supporting this kind of game; the game is FF8
not xxxx.
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 119

Joined: 09 Jun 2013
Posts: 3231

PostPosted: Fri Apr 07, 2017 6:27 pm    Post subject: Reply with quote

I'm sorry, but you don't explain what it is you're trying to accomplish.

The "D" in data needs to be capital:
Code:
Name[y] = trainer.Data.GF

You can now use the multidimensional array called "Name" to retrieve the same data as trainer.Data.GF.
Code:
print(Name[0][0])
Back to top
View user's profile Send private message
bknight2602
Master Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 363

PostPosted: Sat Apr 08, 2017 12:02 pm    Post subject: Reply with quote

Now I feel dumber than usual, but thanks. you asked what was the purpose.
The post was to understand why the little debug code wasn't working, and you pointed that out to me. Ultimately, I am attempting to do something not done by me.

The table records have the following structure:
name1
name1 Description(s)
name1 Abilities Description..--XXX, with XXX representing numbers from 10-250 several to each name throughout the table.
The final coding will:
Identify the correct records i.e. which namex
Ignore any records that don't contain xxx as part of the string.
Change the desired records value to xxx-1

EDIT: And quickly re into another question
Code:
al = getAddressList()
for y = 0, 0 do
for x = 0, addresslist_getCount(al) -1  do
whichGF = trainer.Data.GF[y]
if string.find(whichGF, memoryrecord_getDescription(addresslist_getMemoryRecord(al,x)))  then
print(x .. " " .. whichGF .. " " .. memoryrecord_getDescription(addresslist_getMemoryRecord(al,x)))
end
end
end


Now in this case there are 18 records that begin with Name1, I copied them into each description to ensure. But the out put is only 9 records and worse
the print statement only prints the part of the string (the part matching the string.find)
Quote:
The basic use of string.find is to search for a pattern inside a given string, called the subject string. The function returns the position where it found the pattern or nil if it could not find it. The simplest form of a pattern is a word, which matches only a copy of itself. For instance, the pattern 'hello' will search for the substring "hello" inside the subject string. When find finds its pattern, it returns two values: the index where the match begins and the index where the match ends.


I looked through the table an Name1 exists by itself 9 times, so why weren't the other records that contain more string characters than Name1 included?
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 119

Joined: 09 Jun 2013
Posts: 3231

PostPosted: Sat Apr 08, 2017 9:32 pm    Post subject: Reply with quote

You have the string.find() backwards.
string.find(string_to_search_through, pattern_to_find)
Code:
al = getAddressList()
for y = 0, 0 do
  for x = 0, al.Count - 1  do
    local whichRec = al.MemoryRecord[x]
    local whichGF = trainer.Data.GF[y]
    if string.find(whichRec.Description, whichGF)  then
      print(x .. " " .. whichGF .. " " .. whichRec.Description)
    end
  end
end
Back to top
View user's profile Send private message
bknight2602
Master Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 363

PostPosted: Sat Apr 08, 2017 10:08 pm    Post subject: Reply with quote

Zanzer wrote:
You have the string.find() backwards.
string.find(string_to_search_through, pattern_to_find)
Code:
al = getAddressList()
for y = 0, 0 do
  for x = 0, al.Count - 1  do
    local whichRec = al.MemoryRecord[x]
    local whichGF = trainer.Data.GF[y]
    if string.find(whichRec.Description, whichGF)  then
      print(x .. " " .. whichGF .. " " .. whichRec.Description)
    end
  end
end


You are correct, as usual, but I get an error
if string.find(whichRec.Description, whichGF) then--bad argument #1 to 'find' (string expected, got nil). Now that doesn't make sense, it should be nil for most of the records and bypass the print statement.
I tested printed whichRec and got the table addresses, then tested whichRec.Description and printed nils for all
Back to top
View user's profile Send private message Yahoo Messenger
bknight2602
Master Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 363

PostPosted: Sun Apr 09, 2017 2:44 pm    Post subject: Reply with quote

Thanks to you Zanzer, for your hints and guidance. Here is the code that performs the desired action. Probably not the best coding and I could not make the whichRec.Value to work. So in the old coding style using the data table referenced in the OP.
Code:
                      al = getAddressList()
                      for y = 0, 11 do
                         for x = 0, addresslist_getCount(al) -1  do
                            whichGF = trainer.Data.GF[y]
                            whichRec = memoryrecord_getDescription(addresslist_getMemoryRecord(al,x))
                            if string.find(whichRec, whichGF)  then
                               whichVal3 = string.sub(whichRec, -3)
                               whichVal2 = string.sub(whichRec, -2)
                               if tonumber(whichVal3) then
                                  if tonumber(whichVal3) > tonumber(memoryrecord_getValue(addresslist_getMemoryRecord(al,x))) then
                                     memoryrecord_setValue(addresslist_getMemoryRecord(al,x), tonumber(whichVal3)-1)
                                  end--if tonumber(whichVal3) > tonumber(memoryrecord_getValue(addresslist_getMemoryRecord(al,x))) then
                               elseif tonumber(whichVal2) then
                                  if tonumber(whichVal2) > tonumber(memoryrecord_getValue(addresslist_getMemoryRecord(al,x))) then
                                     memoryrecord_setValue(addresslist_getMemoryRecord(al,x), tonumber(whichVal2)-1)
                                  end--if tonumber(whichVal2) > tonumber(memoryrecord_getValue(addresslist_getMemoryRecord(al,x))) then
                               end--if tonumber(whichVal3) then
                            end--if string.find(memoryrecord_getDescription(addresslist_getMemoryRecord(al,x)), whichGF)  then
                         end--for x = 0, addresslist_getCount(al) -1  do
                      end--for y = 0, 0 do

The code takes a bit of time to complete, as there are 2275 records times 11 loops.
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 339

Joined: 09 May 2003
Posts: 19902
Location: The netherlands

PostPosted: Sun Apr 09, 2017 3:42 pm    Post subject: Reply with quote

off-topic, but just to let other people know who stumble upon this topic
Code:

tonumber(memoryrecord_getValue(addresslist_getMemoryRecord(al,x)))

can be rewritten to
Code:

tonumber(al[x].Value)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Master Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 363

PostPosted: Sun Apr 09, 2017 3:55 pm    Post subject: Reply with quote

If you read through the whole table, why didn't whichRec.Value result in anything but a nil?
But thanks for the tip, I struggle with the new method of record accessing/changing. I never know when and what circumstances allow the .xxxx can be used. I normally get an error message about illegal object or an indexing error.
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 339

Joined: 09 May 2003
Posts: 19902
Location: The netherlands

PostPosted: Sun Apr 09, 2017 4:14 pm    Post subject: Reply with quote

your code doesn't show the use of whichRec.Value so can't really say, but perhaps it didn't return nil, but tonumber did ? (or whichRec didn't get initialized at all, e.g a case wrong somewhere)

tonumber will return nil if it can't parse the value. (e.g '??')


(if you mean your current code:
Code:

whichRec = memoryrecord_getDescription(addresslist_getMemoryRecord(al,x))


then whichRec.Value will of course not function(return nil), as a Description is just a string, no memory record )

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Master Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 363

PostPosted: Sun Apr 09, 2017 4:25 pm    Post subject: Reply with quote

Look at the code Zanzer presented 4 or 5 pots earlier. I copied the exact code and that resulted in nil values, I didn't realize they were nils until I tried to combine in a print statement and got an error message concerning nil values.
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 339

Joined: 09 May 2003
Posts: 19902
Location: The netherlands

PostPosted: Sun Apr 09, 2017 4:49 pm    Post subject: Reply with quote

I tried zanzer's code
Code:

trainer =    {
            Data =    {
                        GF =      {
                                          [0] = "name1";
                                          [1] = "name2";
                                          [2] = "name3";
                                          [3] = "nam4";
                                          [4] = "name5";
                                          [5] = "name6";
                                          [6] = "name7";
                                          [7] = "name8";
                                          [8] = "No One";
                                  };
                     };
            };

al = getAddressList()
for y = 0, 8 do
  for x = 0, al.Count - 1  do
    local whichRec = al.MemoryRecord[x]
    local whichGF = trainer.Data.GF[y]
    if string.find(whichRec.Description, whichGF)  then
      print(x .. " " .. whichGF .. " " .. whichRec.Description .. " "..whichRec.Value)
    end
  end
end


and added two entries named 'name1' and 'name2' and they do give proper results

and it prints the values correctly as well. Remember though that tonumber('??') will return nil

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Master Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 363

PostPosted: Sun Apr 09, 2017 5:01 pm    Post subject: Reply with quote

Copied your code and probably his, resulting in a nil.

Line 22 was the if string.find



2017-04-09_17-55-12.png
 Description:
 Filesize:  38.31 KB
 Viewed:  7147 Time(s)

2017-04-09_17-55-12.png


Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 339

Joined: 09 May 2003
Posts: 19902
Location: The netherlands

PostPosted: Sun Apr 09, 2017 5:13 pm    Post subject: Reply with quote

try
Code:

al = getAddressList()
for y = 0, 8 do
  for x = 0, al.Count - 1  do
    local whichRec = al.MemoryRecord[x]
    local whichGF = trainer.Data.GF[y]

    if (whichRec~=nil) and (whichRec.Description~=nil) then
      if string.find(whichRec.Description, whichGF)  then
        print(x .. " " .. whichGF .. " " .. whichRec.Description .. " "..whichRec.Value)
      end
    else
      if whichRec==nil then
        print("whichRec=nil")
      else
        local cn=whichRec.ClassName
        if cn~=nil then
          print("whichRec="..whichRec.ClassName)
        else
          print("whichRec is fucked")         
        end
        return whichRec, getmetatable(whichRec)
      end
    end
  end
end

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Master Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 363

PostPosted: Sun Apr 09, 2017 5:19 pm    Post subject: Reply with quote

I got a lot of whichRec=TMemoryRecord, so many that the print routine couldn't keep up, but finally finished.


2017-04-09_18-13-01.png
 Description:
 Filesize:  43.87 KB
 Viewed:  7134 Time(s)

2017-04-09_18-13-01.png


Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 339

Joined: 09 May 2003
Posts: 19902
Location: The netherlands

PostPosted: Sun Apr 09, 2017 5:25 pm    Post subject: Reply with quote

what ce version do you use ?
Do you have code with createNativeThread running in your ce in the background ?

do you use special characters in your descriptions ?

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN 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
Goto page 1, 2  Next
Page 1 of 2

 
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