Page 1 of 1

MakeButton

Posted: Wed Aug 10, 2011 5:45 pm
by djrikki
Just an observation, I wasn't expecting this behaviour. Is this a bug?

MakeButton(#IMAGERESIZE, #SIMPLEBUTTON, 177,38,124,34, evtfunc, p_openimageResizeDisplay)

Look at the Userdata field, I am using a Function here. This will be called via msg.userdata in a Switch....Case conditional structure as expected.

Now take a look at this.

MakeButton(#IMAGERESIZE, #SIMPLEBUTTON, 177,38,124,34, evtfunc, p_openimageResizeDisplay(selected$[0])

This time I add parameters into the function set as Userdata.

Now when I run the program, the interpreter calls p_openimageResizeDisplay(selected$[0]) with parameters WHEN THE BUTTON IS CREATED and not as the result of callback.

Also try this:

MakeButton(#IMAGERESIZE, #SIMPLEBUTTON, 177,38,124,34, evtfunc, DebugPrint("here"))

The interpreter will again create the button and launch the userdata straightaway.

Therefore it is not currently possible to set a function that require parameters as userdata.

Re: MakeButton

Posted: Fri Aug 12, 2011 10:23 pm
by Allanon
Try this quick example:

Code: Select all

Function HandleLMB(msg)
   ; Execute your custom function
   msg.userdata.func(msg.userdata.params[0])
EndFunction

...
my_userdata = { func = DebugPrint, params = { "HELLO!" } }
MakeButton( ...., { OnMouseDown = HandleLMB }, my_userdata)
...
This should work

Re: MakeButton

Posted: Fri Aug 12, 2011 10:47 pm
by airsoftsoftwair
@djrikki: What you experience is completely normal behaviour and not a bug. Check the documentation on functions in the Hollywood doc.