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 


Help with error handling when address is not available

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Bit Byte
Advanced Cheater
Reputation: 0

Joined: 28 Nov 2022
Posts: 62

PostPosted: Tue Aug 01, 2023 11:40 am    Post subject: Help with error handling when address is not available Reply with quote

I have script in cheat engine lua that gives error.
let me explain:
This address in the game is created only when my cursor is on an entity body, probably created on the fly and the address gets deleted when I move my cursor away from the entity body.
Code:
local EntityAtCursorBody= getAddress('[[[[[[[[game.exe+1CBBA78]+308]+8]+160]+0]+78]+0]+38]+40')

Now in my lua script while my cursor is on the entity body and I have my right mouse button down some code is executed which works because since the cursor is on the entity the address given above is present
But when my cursor is not on the entity body and I click or have my right mouse button down it gives me error:

Code:
Error:Failure determining what [[[[[[[[game.exe+1CBBA78]+308]+8]+160]+0]+78]+0]+38]+40 means

This is because as I have said before the address is deleted when I move my cursor away from the entity body.
How do I skip or rectify this error?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4724

PostPosted: Tue Aug 01, 2023 12:09 pm    Post subject: Reply with quote

Use `getAddressSafe`, check for nil

Code:
local addr = getAddressSafe(...)
if not addr then
  -- pointer path is not valid: do something, e.g. exit early
  return
end

...

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
gibberishh
Cheater
Reputation: 1

Joined: 30 Aug 2021
Posts: 45

PostPosted: Thu Aug 03, 2023 10:03 pm    Post subject: Reply with quote

I've done this for one of my tables. It checks whether an address exists (the game generates dynamic code), handles errors, displays a helpful message to the user on error, and prevents loading of the rest of the script. If no error, it continues executing the code.

The checking/error handling is done in Lua, the rest of the script is ASM.

Get the table from https://fearlessrevolution.com/viewtopic.php?p=294663#p294663

Will help if you have the game but you should be able to work it out by just reading the code too.

_________________
It's not cheating. It's playing by my rules.
Back to top
View user's profile Send private message
Bit Byte
Advanced Cheater
Reputation: 0

Joined: 28 Nov 2022
Posts: 62

PostPosted: Mon Aug 07, 2023 1:47 pm    Post subject: Reply with quote

Sorry for the late Reply

So for each address or pointer not found in my script I would have to do that for each? Confused

Isn't there any simpler one liner code to completely turnoff error checking & logging, just ignore if not found and move on to execute the next line

Its simple - I dont want errors checked or logged, Ignore/Skip and continue executing the next code even if it comes across any errors.

There are a lot of pointers to addresses that are dynamically created in the game.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4724

PostPosted: Mon Aug 07, 2023 2:29 pm    Post subject: Reply with quote

You're just going to move the error elsewhere...
Code:
-- no error checking
local address = getAddressSafe'...'

-- error now happens here: attempt to perform arithmetic on nil
print(address + 8)

Perhaps there's a better way you could structure your code.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Bit Byte
Advanced Cheater
Reputation: 0

Joined: 28 Nov 2022
Posts: 62

PostPosted: Sat Aug 12, 2023 4:19 am    Post subject: Reply with quote

Thank you for the help

I think i now got past the errors. I used your info like this:

Code:
local Address = getAddressSafe(...)

if Address ~= nil then
  -- execute code
end
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4724

PostPosted: Sat Aug 12, 2023 11:23 am    Post subject: Reply with quote

`~= nil` is superfluous. Normally you'd just do this:
Code:
local Address = getAddressSafe(...)

if Address then
  ...
end

_________________
I don't know where I'm going, but I'll figure it out when I get there.
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 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