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 


Specify AOB table element

 
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: Thu Sep 07, 2023 7:41 pm    Post subject: Specify AOB table element Reply with quote

In this code I search for an AOB that generate two results, what I need help with now is simple: in the for command part, it executes the commands only in the second element of the aob, even without specifying it. I've been trying for hours to specify just the first element but it always modifies the second, only the second. I tried something like: "for i, AddressForComboP2 in ipairs(ResultAobComboP2[0]) do" and it didn't work. I'm probably doing something stupid, so I've come to the conclusion that I need a hand with this.


Code:


{$lua}

[ENABLE]

ResultadoAobComboP2 = AOBScan("01 10 D8 00 28")

for i, EnderecoParaComboP2 in ipairs(ResultadoAobComboP2) do
    EnderecoParaComboP2 = tonumber(EnderecoParaComboP2, 16)
    ValorParaComboP2 = EnderecoParaComboP2 - 17
    print(string.format("%X", EnderecoParaComboP2 - 17))
    print("valor: ", readByte(ValorParaComboP2))
    ValorComboP2 = EnderecoParaComboP2 - 17
    break
end


function ModificarComboP2()
    writeInteger(ValorComboP2, 1)
    print("O valor é: ", readByte(ValorComboP2))
end

if ModificarComboP2T then ModificarComboP2T.destroy(); ModificarComboP2T=nil end
ModificarComboP2T = createTimer()
ModificarComboP2T.interval = 10
ModificarComboP2T.ontimer = ModificarComboP2

[DISABLE]
if ModificarComboP2T then ModificarComboP2T.destroy(); ModificarComboP2T=nil 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: 4702

PostPosted: Thu Sep 07, 2023 8:06 pm    Post subject: Reply with quote

AOBScan returns a stringlist. It's not a Lua table- indexing begins from 0. i.e. `for i = 0, results.Count - 1 do ... end`

Destroy the stringlist after you're done with it.

Don't forget `if syntaxcheck then return end` in {$lua} blocks.

Either that break shouldn't be there or you shouldn't be using a for loop.

Use local variables as the default. Only `ModificarComboP2T` should be a global.

_________________
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 08, 2023 9:37 am    Post subject: Reply with quote

Thanks! I got lost in my own workaround and didn't realize that the for was not necessary. I made some tweaks and it worked thanks to your tips!
_________________
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