Page 1 of 1

name to id

Posted: Thu Dec 12, 2019 9:21 pm
by sashapont
I hate many dynamically generated object with automatic id and names like name="myname"..{I}
Are there any way to get id, for example, for object with name myname100?

Re: name to id

Posted: Fri Dec 13, 2019 4:06 pm
by airsoftsoftwair
You mean you want to look up a variable value using a string? That is possible using the _G symbol, e.g.

Code: Select all

name$ = "myname100"
v = _G[name$]
DebugPrint(v)

Re: name to id

Posted: Fri Dec 13, 2019 5:44 pm
by sashapont
not work for buttons :(

Re: name to id

Posted: Fri Dec 13, 2019 6:04 pm
by airsoftsoftwair
Post your code then... (but make it very short!)

Re: name to id

Posted: Fri Dec 13, 2019 8:40 pm
by sashapont
MakeButton(Nil, #LAYERBUTTON, "button"..t.."box", True, False,{OnMouseDown = p_MyFunc, name="mybutton"})

How I can get id of this button?

Re: name to id

Posted: Fri Dec 13, 2019 9:28 pm
by airsoftsoftwair
Like so:

Code: Select all

buttonid = MakeButton(Nil, #LAYERBUTTON, "button"..t.."box", True, False,{OnMouseDown = p_MyFunc, name="mybutton"})

Re: name to id

Posted: Sat Dec 14, 2019 7:41 pm
by sashapont
I try it and then write
SystemRequest("Attention",ToString(buttonid), "OK",#REQICON_WARNING)

And it doesn't show correct id. What I am doing wrong?

Re: name to id

Posted: Sun Dec 15, 2019 12:10 pm
by airsoftsoftwair
Ok, you need a helper table to achieve what you want, like this:

Code: Select all

idtable = {}
buttonid = MakeButton(Nil, #LAYERBUTTON, "button"..t.."box", True, False,{OnMouseDown = p_MyFunc, name="mybutton"})
idtable[buttonid] = "buttonid"
DebugPrint(idtable[buttonid])