name to id

Discuss any general programming issues here
Post Reply
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

name to id

Post 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?
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: name to id

Post 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)
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

Re: name to id

Post by sashapont »

not work for buttons :(
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: name to id

Post by airsoftsoftwair »

Post your code then... (but make it very short!)
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

Re: name to id

Post by sashapont »

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

How I can get id of this button?
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: name to id

Post by airsoftsoftwair »

Like so:

Code: Select all

buttonid = MakeButton(Nil, #LAYERBUTTON, "button"..t.."box", True, False,{OnMouseDown = p_MyFunc, name="mybutton"})
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

Re: name to id

Post 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?
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: name to id

Post 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])
Post Reply