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 


Freezing element indexes in structures when updating offsets

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3327

PostPosted: Sun Sep 15, 2024 6:11 am    Post subject: Freezing element indexes in structures when updating offsets Reply with quote

Hi all,
CELUA.TXT says:
Code:
getElement(index): Returns a structureElement object (Changing offsets can change the index)

I want to adjust the offset of each element in the structure with a fixed offset programmatically.
I do this with a 'for' loop iterating through each element - getElement(i).
How do I freeze the indexes so I can make sure I apply the offset change to each element once and only once?

Thank you!

PS.
I might be going on about this wrong with a 'for' loop, please let me know if there's a better alternative.
An internal ChangeOffsets() member would be best that does it quickly as there may be quite a lot of members, some even with the same offset.
Thank you!
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Sun Sep 15, 2024 11:25 am    Post subject: Reply with quote

Iterate over the elements twice:
Code:
local s = getStructure(0)

s.beginUpdate()

local elements = {}

for i = 0, s.Count - 1 do
  elements[#elements+1] = s.getElement(i)
end

for i,v in ipairs(elements) do
  -- update offsets here
end

s.endUpdate()

_________________
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 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