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 


attempt to concatenate a userdata value (global 'TopMember')

 
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: 577

PostPosted: Mon Jul 26, 2021 9:13 am    Post subject: attempt to concatenate a userdata value (global 'TopMember') Reply with quote

I'm writing some code for Final Fantasy VII and have run onto a bit of a snag.
Remember there are 9 heroes with three chosen to act.
Code:

local addresslist = getAddressList()
TopMember = addresslist_getMemoryRecordByDescription(addresslist, "Top Char in Party")
MidMember = addresslist_getMemoryRecordByDescription(addresslist, "Mid Char in Party")
BtmMember = addresslist_getMemoryRecordByDescription(addresslist, "Btm Char in Party")
Bat0MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Hero Max Hit Pts (+h37)"))
Bat1MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Barret Max Hit Pts (+h37)"))
Bat2MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Tifa Max Hit Pts (+h37)"))
Bat3MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Aeris Max Hit Pts (+h37)"))
Bat4MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Nanaki Max Hit Pts (+h37)"))
Bat5MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Yuffie Max Hit Pts (+h37)"))
Bat6MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Cait Sith Max Hit Pts (+h37)"))
Bat7MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Vincent Max Hit Pts (+h37)"))
Bat8MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Cid Max Hit Pts (+h37)"))

What I'm attempting to do is to set the top character Hp to
TopMemMaxHp = Bat .. TopMember .. MaxHp where TopMember value is concatenated to form BatXMaxHp where X is the value obtained from
TopMember etc. However when I try this I get an error message listed in the subject line.
Any suggestion to work around the error?
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Mon Jul 26, 2021 9:23 am    Post subject: Reply with quote

TopMember is a memoryrecord, not a value.

You probably want to use TopMember.Value instead

_________________
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
View user's profile Send private message MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Mon Jul 26, 2021 10:07 am    Post subject: Reply with quote

Dark Byte wrote:
TopMember is a memoryrecord, not a value.

You probably want to use TopMember.Value instead


Ok, I inserted TopMember.Value into "TopMemMaxHp = Bat .. TopMember.Value .. MaxHp"
and received another error message
attempt to concatenate a nil value (global 'MaxHp')
I tried adding quotation marks around TopMember.Value also but same result.
I inserted TopMemValue = TopMember.Value and then tried
TopMemMaxHp = Bat .. "TopMemValue" .. MaxHp and obtained the same error message.
When I print TopMember.Value is 0, which is correct in this point int the game.
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Mon Jul 26, 2021 10:21 am    Post subject: Reply with quote

try
Code:

TopMemMaxHp = _G["Bat".. TopMemValue .. "MaxHp"]

_________________
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
View user's profile Send private message MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Mon Jul 26, 2021 10:42 am    Post subject: Reply with quote

Dark Byte wrote:
try
Code:

TopMemMaxHp = _G["Bat".. TopMemValue .. "MaxHp"]


That worked.
That coding is unfamiliar to me would you give a brief description of what _G is?
Back to top
View user's profile Send private message Yahoo Messenger
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Mon Jul 26, 2021 11:35 am    Post subject: Reply with quote

_G is a global variable (not a function) that holds the global environment. Lua itself does not use this variable; changing its value does not affect any environment, nor vice versa.
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Mon Jul 26, 2021 1:49 pm    Post subject: Reply with quote

Thanks
ETA:
Well the code produced a nil value and error of course(Invalid Integer).
Code:

local addresslist = getAddressList();
TopMember = addresslist_getMemoryRecordByDescription(addresslist, "Top Char in Party");
MidMember = addresslist_getMemoryRecordByDescription(addresslist, "Mid Char in Party");
BtmMember = addresslist_getMemoryRecordByDescription(addresslist, "Btm Char in Party");
TopMemValue = TopMember.Value;
MidMemValue = MidMember.Value;
BtmMemValue = BtmMember.Value;
TopMemMaxHp = _G["Bat".. TopMemValue .. "MaxHp"];
print(TopMemMaxHp)
MidMemMaxHp = _G["Bat".. MidMemValue .. "MaxHp"];
BtmMemMaxHp = _G["Bat".. BtmMemValue .. "MaxHp"];
TopMemMaxMp = _G["Bat".. TopMemValue .. "MaxMp"];
MidMemMaxMp = _G["Bat".. MidMemValue .. "MaxMp"];
BtmMemMaxMp = _G["Bat".. BtmMemValue .. "MaxMp"];


Note that this the beginning piece producing the error the later piece to set the value isn't at issue. I printer out the first value but I'm sure they all are producing nil.
TopMemValue, MidMemValue and BtmMemValue all give the appropriate values.
Back to top
View user's profile Send private message Yahoo Messenger
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Mon Jul 26, 2021 4:44 pm    Post subject: Reply with quote

Open the memory viewer window > press Ctrl + L to bring up the Lua Engine, paste your script into the lower pane of the window and click on the left gutter bar on the line that is producing the error then click execute.

The Lua debugger will break on the error so you can see if the variables are holding nil or not.



I hope this explains a bit better.
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Mon Jul 26, 2021 9:14 pm    Post subject: Reply with quote

LeFiXER wrote:
Open the memory viewer window > press Ctrl + L to bring up the Lua Engine, paste your script into the lower pane of the window and click on the left gutter bar on the line that is producing the error then click execute.

The Lua debugger will break on the error so you can see if the variables are holding nil or not.



I hope this explains a bit better.


I have done that, it is why I knew where to put the print statement(the code was copied from the whole code and just put in the new part into the debugger window. The code produces a nil value at
TopMemMaxHp = _G["Bat".. TopMemValue .. "MaxHp"]; and most likely the other two. The concatenate works(no error) but it is a nil.
This is a copy of the output
Code:

local addresslist = getAddressList();
TopMember = addresslist_getMemoryRecordByDescription(addresslist, "Top Char in Party");
MidMember = addresslist_getMemoryRecordByDescription(addresslist, "Mid Char in Party");
BtmMember = addresslist_getMemoryRecordByDescription(addresslist, "Btm Char in Party");
TopMemValue = TopMember.Value;
MidMemValue = MidMember.Value;
BtmMemValue = BtmMember.Value;
TopMemMaxHp = _G["Bat".. TopMemValue .. "MaxHp"];
print(TopMemMaxHp)
MidMemMaxHp = _G["Bat".. MidMemValue .. "MaxHp"];
BtmMemMaxHp = _G["Bat".. BtmMemValue .. "MaxHp"];
TopMemMaxMp = _G["Bat".. TopMemValue .. "MaxMp"];
MidMemMaxMp = _G["Bat".. MidMemValue .. "MaxMp"];
BtmMemMaxMp = _G["Bat".. BtmMemValue .. "MaxMp"];


Nothing beyond the last line, sorry for the way my post may sound no insult is meant by me.
Back to top
View user's profile Send private message Yahoo Messenger
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Tue Jul 27, 2021 5:58 am    Post subject: Reply with quote

Don't worry, I wasn't offended Smile

See how this goes.

Code:

local aList = getAddressList()

TopMember = aList.getMemoryRecordByDescription('Top Char in Party')
MidMember = aList.getMemoryRecordByDescription('Mid Char in Party')
BtmMember = aList.getMemoryRecordByDescription('Btm Char in Party')

if TopMember == nil or MidMember == nil or BtmMember == nil then
   error(ShowMessage('There are no members in the list'))
else if (TopMember ~= nil) and (MidMember ~= nil) and (BtmMember ~= nil) then
      TopMemMaxHP = _G['Bat' .. TopMember.Value .. 'MaxHP']
      MidMemMaxHP = _G['Bat' .. MidMember .Value .. 'MaxHP']
      BtmMemMaxHP = _G['Bat' .. BtmMember .Value .. 'MaxHP']
     end
end
...
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Tue Jul 27, 2021 9:02 am    Post subject: Reply with quote

LeFiXER wrote:
Don't worry, I wasn't offended Smile

See how this goes.

Code:

local aList = getAddressList()

TopMember = aList.getMemoryRecordByDescription('Top Char in Party')
MidMember = aList.getMemoryRecordByDescription('Mid Char in Party')
BtmMember = aList.getMemoryRecordByDescription('Btm Char in Party')

if TopMember == nil or MidMember == nil or BtmMember == nil then
   error(ShowMessage('There are no members in the list'))
else if (TopMember ~= nil) and (MidMember ~= nil) and (BtmMember ~= nil) then
      TopMemMaxHP = _G['Bat' .. TopMember.Value .. 'MaxHP']
      MidMemMaxHP = _G['Bat' .. MidMember .Value .. 'MaxHP']
      BtmMemMaxHP = _G['Bat' .. BtmMember .Value .. 'MaxHP']
     end
end
...

Ok today is a new day and some aspects look better.
Code:

local addresslist = getAddressList();
TopMember = addresslist_getMemoryRecordByDescription(addresslist, "Top Char in Party");

TopMember is a value of then memory record with the associated description with a current value of 0.
Code:
 
MidMember = addresslist_getMemoryRecordByDescription(addresslist, "Mid Char in Party");
BtmMember = addresslist_getMemoryRecordByDescription(addresslist, "Btm Char in Party");
TopMemValue = TopMember.Value;
MidMemValue = MidMember.Value;
BtmMemValue = BtmMember.Value;
Bat0MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Hero Max Hit Pts (+h37)"))
Bat1MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Barret Max Hit Pts (+h37)"))
Bat2MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Tifa Max Hit Pts (+h37)"))
Bat3MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Aeris Max Hit Pts (+h37)"))
Bat4MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Nanaki Max Hit Pts (+h37)"))
Bat5MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Yuffie Max Hit Pts (+h37)"))
Bat6MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Cait Sith Max Hit Pts (+h37)"))
Bat7MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Vincent Max Hit Pts (+h37)"))
Bat8MaxHp = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,"Cid Max Hit Pts (+h37)"))
TopMemMaxHp = "Bat".. TopMemValue .. "MaxHp";

These work now. The current string is correct, Bat0MaxHp. Now I need to attach a memory record that this string represents. The string should point back to memory record "Hero Max Hit Pts (+h37)" which has a value of 739.
Code:

memoryrecord_getValue(addresslist_getMemoryRecordByDescription(addresslist,TopMemMaxHp_String))
MidMemMaxHp = "Bat".. MidMemValue .. "MaxHp";
BtmMemMaxHp = "Bat".. BtmMemValue .. "MaxHp";
TopMemMaxMp = "Bat".. TopMemValue .. "MaxMp";
MidMemMaxMp = "Bat".. MidMemValue .. "MaxMp";
BtmMemMaxMp = "Bat".. BtmMemValue .. "MaxMp";

So how would this(and the other two) string point to the correct memory records?

This is a somewhat old table and I stated using the original coding and that is why the coding looks the way it does. I'm trying not to mix the new with the old, but if I have to then I'll do it.
An if statement will need to be used for the second and third characters nil won't work but 255 will work.
Back to top
View user's profile Send private message Yahoo Messenger
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Tue Jul 27, 2021 1:13 pm    Post subject: Reply with quote

bknight2602 wrote:

Ok today is a new day and some aspects look better.
Code:

local addresslist = getAddressList();
TopMember = addresslist_getMemoryRecordByDescription(addresslist, "Top Char in Party");


TopMember is a value of then memory record with the associated description with a current value of 0.

Here you can replace the underscore, with the period character, and remove the addresslist parameter within the parenthesis.

Code:

TopMember = addresslist.getMemoryRecordByDescription("Top Char in Party");


TopMember then becomes a memory record which is accessible like so

Code:

local TopMemberString = TopMember.Description
local TopMemberValue = TopMember.Value
...


And so on.

It's not so much about mixing new with old but fixing the issues. Cheat Engine is heavily object based and these objects contain properties, methods (functions) etc...

When we reference an object with Lua we have access to those properties and methods.

For example:
Code:

local al = getAddressList()
if al ~= nil then
   for i = 0, al.Count -1 do
     print(al[i].Description)
   end
end


It helps to understand how the objects interact with one another to know what the problem is.

Note: For some reason it appears that the use of the variable name "addresslist" is treated as a keyword.
Back to top
View user's profile Send private message
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