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 


ignore "out of bounds error"

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
MustangNil
Newbie cheater
Reputation: 0

Joined: 13 Jun 2022
Posts: 12
Location: South America

PostPosted: Fri Sep 22, 2023 10:01 pm    Post subject: ignore "out of bounds error" Reply with quote

I ended up in a very specific situation, I need to choose index 46 of the AOB if it exists, but if I do an if and it doesn't exist, the "out of bounds" error will obviously occur, so... what do I do? Is there any way to ignore this error and jump to the else block?

Code:


ResultadoAobGuidlineP1 = AOBScan("00 00 31 40 00 00 00 00 00 00 2C 40")


if ResultadoAobGuidlineP1[46] then
    EnderecoParaGuidlineP1 = ResultadoAobGuidlineP1[36]
else
    EnderecoParaGuidlineP1 = ResultadoAobGuidlineP1[14]
end

_________________
As always, with doubts...
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4715

PostPosted: Fri Sep 22, 2023 10:28 pm    Post subject: Reply with quote

You can check how many elements there are with the "Count" property
Code:
local results = AOBScan('...')
local whatever

-- AOBScan returns nil on failure
if results then
  if results.Count >= 47 then
    whatever = results[36]
  elseif results.Count >= 15 then
    whatever = results[14]
  end

  -- don't forget to destroy the stringlist (if it exists)
  results.destroy()
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
MustangNil
Newbie cheater
Reputation: 0

Joined: 13 Jun 2022
Posts: 12
Location: South America

PostPosted: Fri Sep 22, 2023 10:44 pm    Post subject: Reply with quote

It worked perfectly, thank you very much!
_________________
As always, with doubts...
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