Page 1 of 1
What is "pBtnNum"?
Posted: Wed May 22, 2013 7:31 pm
by makeshyft
Hi,
I've come across a couple of sample scripts that use "pBtnNum" in the script. I have force variable declaring on, and the script runs fine, leading me to conclude this is NOT a user variable.
Example script:
on mouseUp pBtnNum
global theChosenColor
if pBtnNum is 1 then
## Prompt user for color using current color as default
answer color with the effective backgroundcolor of me
## If user didn't cancel then assign background color
## to chosen color
if the result is not "cancel" then
put it into theChosenColor
set the backgroundcolor of me to theChosenColor
end if
end if
answer theChosenColor
end mouseUp
What does this refer to?
Thanks
Re: What is "pBtnNum"?
Posted: Wed May 22, 2013 7:35 pm
by FourthWorld
Looking in the Dictionary for the mouseUp message, it says:
Parameters:
The mouseButtonNumber specifies which mouse button was pressed:
* 1 is the mouse button on Mac OS systems and the left button on Windows and Unix systems.
* 2 is the middle button on Unix systems.
* 3 is the right button on Windows and Unix systems and Control-click on Mac OS systems.
http://livecode.com/developers/api/5.0.2//mouseUp/
Re: What is "pBtnNum"?
Posted: Wed May 22, 2013 7:44 pm
by makeshyft
Oh Geez... that makes perfect sense....lol. I did a search for it, and nothing came up. Thanks
Re: What is "pBtnNum"?
Posted: Wed May 22, 2013 9:19 pm
by dunbarx
Hi.
But much more importantly, this term, and its name is arbitrary and up to you, is a parameter associated with the message itself. This is a built-in parameter, and though it is not required for the handler to work, it provides additional information to the engine.
There are naming conventions that many here follow, as it helps to have a common lexicon. The "p" is one of those common prefixes. "t" is another for local variables.
But this could have just as well have been:
on mouseUp theButtonYouHeldDown
You will encounter these sorts of things more when you deal with functions, custom functions and custom handlers, where several parameters may be passed along with the message name. When you get the hang of them, they provide enormous power to the language.
Craig Newman
Re: What is "pBtnNum"?
Posted: Wed May 22, 2013 11:14 pm
by Simon
Hi Craig,
Is there a way to show all the passed preferences?
on mouseDown
put the parameters passed --???
end mouseDown
A way to display information (I can see it's in the dictionary) that may get overlooked?
Thanks,
Simon
Re: What is "pBtnNum"?
Posted: Wed May 22, 2013 11:36 pm
by dunbarx
Simon.
Do you mean something like this? In a button script:
on mouseup
showparams a,b,c
end mouseUp
on showparams
answer the params
end showparams
I still cannot get my "code" helper to work, and I have seen others using it.
Craig
Re: What is "pBtnNum"?
Posted: Wed May 22, 2013 11:40 pm
by Simon
Nice!
Thanks Craig.
Simon