Finding out the name of unknown DImageButton

I made a loop that creates DImageButtons and to check to see if they all got the same name I tried to remove them, only the last one removed. I want them to have unique names but I don’t know how to change their name or identify what they are.
The reason for the loop is that I am having them appear in a row and they are automatically picking their texture.
It’s probably something simple but I’ve been messing with it for hours. I hate asking questions.

[editline]04:31AM[/editline]

How did that happen… I was in the Newbie section. Can a mod move this?

When you’re making the button, you can set a variable on the button as simple as

[lua]local btn = vgui.Create(“DImageButton”)
btn.ButtonName = “A Name”
if btn.ButtonName == “Your Name” then
– Do things
end[/lua]

btn.ButtonName will start placing them in a table right? Will it automatically add them to the end or would it keep overwriting the same slot?
Also do you know of a way to easily display everything in a table?
I’d really like to know what the other buttons think they are if they aren’t what I first called them anymore.

You could always create a table of panels and use the table index.

Please post the code you’re using to generate them, loop and all. It will make it much simpler.

Yes sir, will do. I’ll make a guess at code tags but I’m not sure it will work.



function buttonSpawner()
gui.EnableScreenClicker( true )
for e = 0, 5 do
for i = 0, 9 do
local blah = e * 10
buttonName = vgui.Create( "DImageButton", DermaPanel )
buttonName:SetPos( i * 60, e * 85 )
buttonName:SetSize( 60, 85 ) -- Size of the frame
local imageIndex = endTable[blah + i + 1]
imageIndex = tonumber( imageIndex)
buttonName:SetImage( cardImage[imageIndex] ) -- Set your .vmt file
buttonName.DoClick = function()
    Msg("
Left click works.") -- What happens when you press the image
    buttonName.DoRightClick = function()
    Msg("
Right click works" )
    
end
end
end
end
end


It didn’t number it, I tried [lua] and



Each card gets the name buttonName at first, then after the next one is created the previous ones stop responding to it.

Tab your code like this, i also added a few comments :

[lua]function buttonSpawner()
//gui.EnableScreenClicker( true ) // Not needed, the clicker is shown when a derma panel is active.
for e = 0, 5 do
for i = 0, 9 do
local blah = e * 10
local buttonName = vgui.Create( “DImageButton”, DermaPanel ) // Use locals.
buttonName:SetPos( i * 60, e * 85 )
buttonName:SetSize( 60, 85 ) – Size of the frame
local imageIndex = tonumber(endTable[blah + i + 1]) // Compacted to a single line.
buttonName:SetImage( cardImage[imageIndex] )
buttonName.DoClick = function()
Msg("
Left click works.") – What happens when you press the image
end
buttonName.DoRightClick = function() // Moved thisone outside DoClick (Else you need to press normaly first before you can rightclick)
Msg("
Right click works" )
end
end
end
end][/lua]

You need to keep a reference to them. A good way to do it would be inserting them in a table where you can easilly keep track of them.

For example MyPanels[e]* = buttonname

Note that you would have to define MyPanels[e] first.

Yay, all is well now. Thanks. Also Kialtia I completely forgot to tab. I guess I was to preoccupied with things going wrong and trying to fix them. I’ll try to tab from now on.