View previous topic :: View next topic |
Author |
Message |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Tue Jul 02, 2019 10:38 am Post subject: Using Tag and this.Control in Lua |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Tue Jul 02, 2019 1:00 pm Post subject: |
|
|
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 |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Tue Jul 02, 2019 7:50 pm Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Tue Jul 02, 2019 11:57 pm Post subject: |
|
|
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 |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Wed Jul 03, 2019 12:11 am Post subject: |
|
|
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 |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Thu Jul 04, 2019 9:35 pm Post subject: |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Thu Jul 04, 2019 11:00 pm Post subject: |
|
|
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 |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Fri Jul 05, 2019 5:57 am Post subject: |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Sat Jul 06, 2019 11:52 pm Post subject: |
|
|
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 |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sun Jul 07, 2019 6:35 am Post subject: |
|
|
Dark Byte wrote: | Or just use a table |
Sure, DB.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
 |
|