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 


Setting Table value

 
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 Jul 17, 2019 10:35 am    Post subject: Setting Table value Reply with quote

I know this must be simple but I haven't found the correct answer.
Code:
al = getAddressList();
myitem = memoryrecord_getAddress(addresslist_getMemoryRecordByDescription(al, "Unequipped Item Dagger Num"))
  for x =0, 252 do
   myitem.Value = 14
  end

The code identifies the correct table location, but I get "attempt to index a number value (global 'myitem')
Script Error"
So what is the correct way to change the value?

ETA: I knoiw there should be a myitem = myitem + 1 in the code.
Back to top
View user's profile Send private message Yahoo Messenger
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Wed Jul 17, 2019 1:34 pm    Post subject: Reply with quote

don't get the address just use the memory record.
Also the variable AddressList was added instead of having to call the function and it's a complete userdata object now so you can call methods on it rather than having to pass it around so you can do just
Code:

myitem = AddressList.getMemoryRecordByDescription('Unequipped Item Dagger Num')
myitem.Value = 14 -- or whatever, the loop makes no sense even with a +1

If you're getting a lot of records and want to save some typing without using a table and loop then you can do
Code:

local getmr = AddressList.getMemoryRecordByDescription
myitem = getmr('Unequipped Item Dagger Num')
...


If "Num" in the the description/name is supposed to be an actual number eg 'Unequipped Item Dagger 0' then the loop makes more sense lol and you'd do something like
Code:
for i=0,252 do
  local mr = getmr('Unequipped Item Dagger ' .. i)
  mr.Value = mr.Value + 1
end
or
Code:
for i=0,AddressList.Count do
  local mr = AddresList[i]
  if mr.Description:find('Unequipped Item Dagger %d') then
    mr.Value = mr.Value + 1
  end
end
which would work for any number of items without having to hardcode it and risk it breaking if more are added or any removed at some point.
_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Wed Jul 17, 2019 1:54 pm    Post subject: Reply with quote

FreeER wrote:
don't get the address just use the memory record.
Also the variable AddressList was added instead of having to call the function and it's a complete userdata object now so you can call methods on it rather than having to pass it around so you can do just
Code:

myitem = AddressList.getMemoryRecordByDescription('Unequipped Item Dagger Num')
myitem.Value = 14 -- or whatever, the loop makes no sense even with a +1

I'm attempting to increment the address locations by one.
Quote:

If you're getting a lot of records and want to save some typing without using a table and loop then you can do
Code:

local getmr = AddressList.getMemoryRecordByDescription
myitem = getmr('Unequipped Item Dagger Num')
...


This gives the similar type of error like I was getting.
Quote:

If "Num" in the the description/name is supposed to be an actual number eg 'Unequipped Item Dagger 0' then the loop makes more sense lol and you'd do something like
Code:
for i=0,252 do
  local mr = getmr('Unequipped Item Dagger ' .. i)
  mr.Value = mr.Value + 1
end
or
Code:
for i=0,AddressList.Count do
  local mr = AddresList[i]
  if mr.Description:find('Unequipped Item Dagger %d') then
    mr.Value = mr.Value + 1
  end
end
which would work for any number of items without having to hardcode it and risk it breaking if more are added or any removed at some point.


Thanks for replying. The Num is a descriptor, it has no value, the value is at the address. As I said the addresses incriminate by one.

ETA:
Tinkering around most of the day, This works
Code:
al = getAddressList();
myitem = memoryrecord_getAddress(addresslist_getMemoryRecordByDescription(al, "Unequipped Item Dagger Num"))
  for x =0, 252 do
    writeBytes(myitem, 14)
    myitem = myitem + 0x01
  end--for x =0, 252 do
end;--function (sender)


Now I don't understand how +1 fails, but 0x01 succeeds.
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