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 


How do I know if an address is allocated?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Sat Jul 01, 2017 9:09 pm    Post subject: How do I know if an address is allocated? Reply with quote

In Lua I have a list with addresses, what interests me in them is to read its value with 'readInteger ()', however it has a problem, some of these addresses are sometimes not allocated, that is, they get the value = ??.
When I make a comparison to the value of these invalid addresses I get an error.
How can I check if this address is allocated and stop receiving errors?

_________________
...
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Jul 02, 2017 12:43 pm    Post subject: Reply with quote

Code:
local value = readInteger(address)
if value and value > 0 then
  -- yay
end
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Jul 02, 2017 5:22 pm    Post subject: Reply with quote

@Zanzer, why value > 0? After all normal values could legitimately be negative...

example explanation stuff:
Code:
address = "5"
local value = readInteger(address)
print(tostring(value))


where an address of 5 is obviously bad shows that the return value is nil (and doesn't create an error that stops the script unlike, say, getAddress("[5]")) which would be caught by the if value check since nil is treated as a false value.

Alternatively if you have a memory record and access it's value then it will be "??"

Code:
al = getAddressList()
mr = al.getMemoryRecord(0) -- get first record in list for testing, again address of 5
print(tostring(mr.value)) -- ??
print(tostring(mr.value == "??")) -- true
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon Jul 03, 2017 2:23 pm    Post subject: Reply with quote

You said you wanted to "make a comparison" so value > 0 was an example of a comparison.
The important part was before it. It checks to make sure it's not nil.
Code:
if value then
  -- do stuff
end
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