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?
name to id
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: name to id
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)
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: name to id
Post your code then... (but make it very short!)
Re: name to id
MakeButton(Nil, #LAYERBUTTON, "button"..t.."box", True, False,{OnMouseDown = p_MyFunc, name="mybutton"})
How I can get id of this button?
How I can get id of this button?
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: name to id
Like so:
Code: Select all
buttonid = MakeButton(Nil, #LAYERBUTTON, "button"..t.."box", True, False,{OnMouseDown = p_MyFunc, name="mybutton"})
Re: name to id
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?
SystemRequest("Attention",ToString(buttonid), "OK",#REQICON_WARNING)
And it doesn't show correct id. What I am doing wrong?
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: name to id
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])