Way to see layers attached button and access its userdata?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1180
Joined: Sun Feb 14, 2010 7:11 pm

Way to see layers attached button and access its userdata?

Post by Bugala »

Thought it was handiest using buttons msg.userdata for the task, but now after having implemented that for many many times in my code, i suddenly notice i would need to access that data outside of button being activated, and cant figure out a way to do that.

Thing is, I would need two things:

1. I only have access to the layers name. Is there a way to figure out which button is attached to it? GetAttribue didnt seem to help, as first of all, it doesnt have anything for buttons, and at #LAYERS it doesnt give option to query for the button that is attached to that layer (future feature wish)

2. I could use SetObejctData for that layer to attach that buttons ID for that layer, but is there any way to access buttons "userdata" without actually activating the button?


Only solution that comes to my mind is to do whole load of rewriting and implement setobjectdata/getobjectdata for the layers that represents the button instead of using buttons msg.userdata, but is that really the only solution?
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Way to see layers attached button and access its userdat

Post by airsoftsoftwair »

It's currently not possible to find out the button id using the layer id but as you said, you can just use SetObjectData() to workaround this limitation. You can store the button id as well as the button's user data inside the layer using two successive calls to SetObjectData(). SetObjectData() can deal with arbitrary data types so you can also just set the button's user data to the layer's object data. This is all very cheap and doesn't use major resources because everything is copied by reference.
Bugala
Posts: 1180
Joined: Sun Feb 14, 2010 7:11 pm

Re: Way to see layers attached button and access its userdat

Post by Bugala »

I ended up doing something you shouldnt do.

I am inventing AAA chipset and AGA at same time.

By otherwords, I am using msg.userdata where i have already used it, and implementing to everything new a workaround where i am putting that userdata instead to Layer with SetObjectData(). I just hope I will be able to avoid situation where bug relies in me changing layers userdata, and then thinking msg.userdata was changed too or vice versa, since thats the risk of using them both at same time. I just felt it was too much trouble to rewrite things by erasing the msg.userdata completely, which had been the best solution.
Post Reply