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 


Using Tag and this.Control in Lua

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Tue Jul 02, 2019 10:38 am    Post subject: Using Tag and this.Control in Lua Reply with quote

Hi there. Is somebody knows about using 'Tag' and 'this.Controls' in Lua?

Example in C#:

Code:
object.Tag = "sonething" //string
this.Controls.Add(object)


From openRB/Logic Machine/Docs/Lua:

Code:
grp.tag(tags [, mode])

Returns table containing objects with the given tag. Tags parameter can be either a table or a string. The mode parameter can be either 'or' (default — returns objects that have any of given tags) or 'and' (return objects that have all of given tags). You can use object functions on the returned table.


But no example there. I just want to learn how using 'Tag' and 'this.Controls.Add()' in CE Lua if possible.

Thank you

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25796
Location: The netherlands

PostPosted: Tue Jul 02, 2019 1:00 pm    Post subject: Reply with quote

Tag can only be a 64-bit integer

You can use a table and let that tag reference an item in that table.

Also, table entries can be tables themselves so you can store a huge amount of addition info just by giving a simple tag

the ref system is a special table that is great to use for this (createRef()/getRef(), but you can of course allocate your own global table)

e.g.:
Code:

f=createForm()
button=createButton(f)
buttondata={}
buttondata.something='important'
button.Tag=createRef(buttondata)
button.Caption='Click Me'
button.AutoSize=true

button.OnClick=function(sender)
  showMessage(getRef(sender.Tag).something)
end


or using your own table:
Code:

if mytable==nil then
  mytable={}
end

f=createForm()
button=createButton(f)
buttondata={}
buttondata.something='important'
button.Tag=#mytable+1
mytable[#mytable+1]=buttondata

button.Caption='Click Me'
button.AutoSize=true

button.OnClick=function(sender)
  showMessage(mytable[sender.Tag].something)
end


_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping


Last edited by Dark Byte on Tue Jul 02, 2019 11:46 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Tue Jul 02, 2019 7:50 pm    Post subject: Reply with quote

Wow, clear and detail DB. I will try the method you explained in my project. Let see next.
Thank so much

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Jul 02, 2019 11:57 pm    Post subject: Reply with quote

If you need tag to hold more data other than a number, allocate a block of memory and set the tag of an object to the pointer to said data. Then manually read the data back from the tag pointer value as needed.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Wed Jul 03, 2019 12:11 am    Post subject: Reply with quote

atom0s wrote:
If you need tag to hold more data other than a number, allocate a block of memory and set the tag of an object to the pointer to said data. Then manually read the data back from the tag pointer value as needed.


Thanks, @atom0s, let me study and try to implement the method first. If I found something not understand, Next I will ask here. Please don't feel bothered and bored.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu Jul 04, 2019 9:35 pm    Post subject: Reply with quote

Ok, next is part of what I did on my project.

Code:
GameForm=createForm()
GameForm.setSize(939,705)

enemie1=createImage(GameForm)
enemie1.setPosition(50,100)
enemie1.setSize(71,71)
enemie1.AutoSize=true
enemie1.loadImageFromFile(resourcepath..'zdown.png')

enemie2=createImage(GameForm)
enemie2.setPosition(450,140)
enemie2.setSize(71,71)
enemie2.AutoSize=true
enemie2.loadImageFromFile(resourcepath..'zdown.png')

player=createImage(GameForm)
player.setPosition(270,270)
player.setSize(71,71)
player.Stretch=true
player.loadImageFromFile(resourcepath..'sUp.png')

enemiedata={}
enemiedata='enemie'
ammodata={}
ammodata='ammo'

enemie1.Tag=createRef(enemiedata)
enemie2.Tag=createRef(enemiedata)

// and so on


Now, I need to check every component on the GameForm by their type. I was checked in CE Lua Component class but didn't found 'getComponent() by type'.

In C# I can do like this:

Code:
foreach (Control x in this.Controls)
{
 if (x is PictureBox && x.Tag == "ammo";
  // some conditions
 this.Controls.Remove(((PictureBox)x))
}


The questions:
1. Am I set 'Tag' for objects already on the right way, on the script above?
2. How I get components by their type/class, if possible?
3. How to implement the last C# script above?.

I imagine something like this:

Code:
compotype = GameForm.getComponentByType()

for x in GameForm do
 if compotype  == CEImage and x.Tag == 'ammo'
   // do something
  compotype.destroy()
 end
end


Thank you for any explanations and help.
Regards

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25796
Location: The netherlands

PostPosted: Thu Jul 04, 2019 11:00 pm    Post subject: Reply with quote

Code:

enemiedata={}
enemiedata='enemie'

you're overriding enemiedata with the string 'enemie'
if you only want a single string that's ok, but uf you need more data best use the table instead


2: get all components and then check if their ClassName property matches with what you need

3:
Code:

for i=GameForm.ComponentCount-1,0,-1 do
  local x=GameForm.Component[i]
  if (x.ClassName=='TCEImage') and (getRef(x.Tag)=='ammo') then
    x.destroy()
  end
end

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Jul 05, 2019 5:57 am    Post subject: Reply with quote

Ahh, I see that. The ClassName.

Thanks, DB, I try instructions from you first

EDIT:
I noticed, using Tag make consume memory (memory leak), as atom0s said, need to allocate some memory block. So, it better uses Lua meta table.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25796
Location: The netherlands

PostPosted: Sat Jul 06, 2019 11:52 pm    Post subject: Reply with quote

Or just use a table
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sun Jul 07, 2019 6:35 am    Post subject: Reply with quote

Dark Byte wrote:
Or just use a table

Sure, DB.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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