MakeButton to return ID also when ID is given

Feature requests for future versions of Hollywood can be voiced here
Post Reply
Bugala
Posts: 1329
Joined: Sun Feb 14, 2010 7:11 pm

MakeButton to return ID also when ID is given

Post by Bugala »

To demonstrate:

Code: Select all

ID=2
NewID = MakeButton(ID, #SIMPLEBUTTON, 100, 100, 100, 100, {OnMouseDown = Function() DebugPrint("mouse down") EndFunction})
DebugPrint(NewID)
WaitEvent()
If you change ID to nil, it gives userdata.

I was having in my program a makebutton function, which sends, along the other data, ButtonID, which might be a fixed number, or a NIL.

The program at that point is not supposed to know whether there is a number or NIL, but it is supposed to catch it to Button.ButtonID variable.

Now problem is that if I am using:
Button.ButtonID = MakeButton(...

then if it is sent a fixed number, it fails, since it doesn't return the ButtonID:

Therefore, it would be good if MakeButton would return ButtonID in every case, regardless if it is NIL, userdata, or actual number.

This is also what you would expect from the description code in manual:
[id] = MakeButton(id, #SIMPLEBUTTON, x, y, width, height, t[, userdata])
User avatar
emeck
Posts: 188
Joined: Fri Apr 03, 2015 3:17 pm

Re: MakeButton to return ID also when ID is given

Post by emeck »

@Bugala
From the description, the returned "id" will only be returned when you pass Nil as the "id" argument to the function. And that is also consistent with other functions like CreateAnim() or CreateBrush() for example.

Using Nil makes use of Hollywood's "private" pool of IDs, which doesn't mix with the numbers you can use to assign to your objects if you need.

The advantage of Nil for IDs is that way you can manage your objects' IDs easier by names instead of numbers when you have a large collection of numbers.

I don't know were the user data you see comes from, but you either use Nil or pass an ID to the object you need to create. I don't think mixing both is a good idea, unless I have misunderstood something.

Regards

Edit: typo
PowerBook 5.8 MorphOS 3.18
Mac Mini MorphOS 3.18
Flinx
Posts: 280
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: MakeButton to return ID also when ID is given

Post by Flinx »

And if you think you really need it in this way, then you could make your own function:

Code: Select all

Function p_MakeButton(ID, ...)
	Local nid=MakeButton(ID, Unpack(arg))
	If IsNil(nid) Then nid=ID
	Return(nid)
EndFunction

ID=2
NewID = p_MakeButton(ID, #SIMPLEBUTTON, 100, 100, 100, 100, {OnMouseDown = Function() DebugPrint("mouse down") EndFunction})
DebugPrint(NewID)
WaitEvent()
User avatar
jPV
Posts: 688
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: MakeButton to return ID also when ID is given

Post by jPV »

Flinx wrote: Sat Mar 08, 2025 10:46 am And if you think you really need it in this way, then you could make your own function:
+1

Nice and easy solution, not everything should be offered by Hollywood itself when you can do your own custom features when you need them, that's called "programming" :D
Bugala
Posts: 1329
Joined: Sun Feb 14, 2010 7:11 pm

Re: MakeButton to return ID also when ID is given

Post by Bugala »

@flinx

Thanks!
That works and solves my problem of needing to do two different makebuttons.
Post Reply