common buttons with different labels
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
common buttons with different labels
I have buttons numbered (labelled 1-9 and a-z) and on mouseDown, I want to use the label/value of that key. Is there an easier way to do it than writing a handler for each one?
I tried giving each button the same name and putting one handler for that name on the card script but that did not work.
Any suggestions?
I tried giving each button the same name and putting one handler for that name on the card script but that did not work.
Any suggestions?
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: common buttons with different labels
Hi.
Don't use numbers for names. Just don't. This is not prohibited, but, well, if you do, you will soon get flummoxed. Go back and name your buttons "a1", "a2" or something like that if your scheme warrants that sort of thing.
Put something like this in your card script:
Make sure there is no "mouseUp" handler in any of your buttons, or if there is, that the last line reads: "pass mouseUp".
This gets into fundamental knowledge of the message and hierarchy workings of LiveCode. You MUST practice this sort of thing, Why does this simple handler in the card script work at all? What would happen if the central code line read simply: "answer the target". How could you work this so that buttons on more than one card were also dealt with?
Write back...
Craig Newman
Don't use numbers for names. Just don't. This is not prohibited, but, well, if you do, you will soon get flummoxed. Go back and name your buttons "a1", "a2" or something like that if your scheme warrants that sort of thing.
Put something like this in your card script:
Code: Select all
on mouseup
if button is in the target then answer the target
end mouseup
This gets into fundamental knowledge of the message and hierarchy workings of LiveCode. You MUST practice this sort of thing, Why does this simple handler in the card script work at all? What would happen if the central code line read simply: "answer the target". How could you work this so that buttons on more than one card were also dealt with?
Write back...
Craig Newman
Re: common buttons with different labels
I tried that and got the message:dunbarx wrote:Hi.
Don't use numbers for names. Just don't. This is not prohibited, but, well, if you do, you will soon get flummoxed. Go back and name your buttons "a1", "a2" or something like that if your scheme warrants that sort of thing.
Put something like this in your card script:Make sure there is no "mouseUp" handler in any of your buttons, or if there is, that the last line reads: "pass mouseUp".Code: Select all
on mouseup if button is in the target then answer the target end mouseup
This gets into fundamental knowledge of the message and hierarchy workings of LiveCode. You MUST practice this sort of thing, Why does this simple handler in the card script work at all? What would happen if the central code line read simply: "answer the target". How could you work this so that buttons on more than one card were also dealt with?
Write back...
Craig Newman
compilation error (Expression: double binary operator) near "is", char 7)
I don't understand?
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: common buttons with different labels
that's probably because he made a small error in that example, just to test if you've actually learned, or simply copy pasted his code without thinking 

Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Re: common buttons with different labels
Hi nbewbie4,
no idea what the engine is complaining about but try this:
Please take Craigs advice and use the LABEL (what you see on the screen <> the NAME of a button!)
for your "numbering" conventions, with the above script you should be able to do whatever you want to do
Best
Klaus
no idea what the engine is complaining about but try this:
Code: Select all
on mouseup
if word 1 of the target = "button" then
answer the label of target
end if
end mouseup
for your "numbering" conventions, with the above script you should be able to do whatever you want to do

Best
Klaus
Re: common buttons with different labels
Bjoernke was being kind. If I actually tried the script, instead of just winging it, I might have put "button" in quotes, like a good boy.
And newbie, the reason not to use numbers as names is that these frequently conflict. You will, many times, want to do something with "button 3". The engine will not be able to distinguish between the third button, and a button named "3". That is the reason NOT to do this, ever. Trust us.
But the label, as opposed to the name, is not subject to this confusion, because LC does not allow one to order a control by label. It is just that, text that is displayed, and though it is a property like any other, it will not conflict in the same way. I generally use names alone; rarely do I need a label as well, and "naming" controls properly causes no problems. But labels have their uses, and you generally find them to be helpful when the situation calls for an extra layer of identification.
You may have skirted this, obliquely, when you tried using the same name for many buttons, trying to corral them with a single handler. This was clever, but presumptuous. You HAVE to get this message/hierarchy knowledge firmly implanted. it is the rock bottom foundation for developing as a programmer in this environment, is easy to understand, and contains enormous power.
You have not answered my three questions...
Craig
And newbie, the reason not to use numbers as names is that these frequently conflict. You will, many times, want to do something with "button 3". The engine will not be able to distinguish between the third button, and a button named "3". That is the reason NOT to do this, ever. Trust us.
But the label, as opposed to the name, is not subject to this confusion, because LC does not allow one to order a control by label. It is just that, text that is displayed, and though it is a property like any other, it will not conflict in the same way. I generally use names alone; rarely do I need a label as well, and "naming" controls properly causes no problems. But labels have their uses, and you generally find them to be helpful when the situation calls for an extra layer of identification.
You may have skirted this, obliquely, when you tried using the same name for many buttons, trying to corral them with a single handler. This was clever, but presumptuous. You HAVE to get this message/hierarchy knowledge firmly implanted. it is the rock bottom foundation for developing as a programmer in this environment, is easy to understand, and contains enormous power.
You have not answered my three questions...
Craig
Re: common buttons with different labels
This worked:
I named the buttons - "b1", "b1", "ba", "bb", etc and used the following script on the card
on mouseUp
local tKey
put the short name of the target into tKey
put the second char of tKey into field "Field1"
end mouseUp
There must be a less awkward way of doing this, I will keep trying.
Sorry about your questions, I am still working on them. (e.g. "target" is a new term to me. I have to read up on it and how to use it)
But thanks for your help
I named the buttons - "b1", "b1", "ba", "bb", etc and used the following script on the card
on mouseUp
local tKey
put the short name of the target into tKey
put the second char of tKey into field "Field1"
end mouseUp
There must be a less awkward way of doing this, I will keep trying.
Sorry about your questions, I am still working on them. (e.g. "target" is a new term to me. I have to read up on it and how to use it)
But thanks for your help
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: common buttons with different labels
Hi Newbie4,
so you might want to add my "if...then..." clause.
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Good, but this script will also execute when you click on the "naked" card (not on a button!)Newbie4 wrote:This worked:
I named the buttons - "b1", "b1", "ba", "bb", etc and used the following script on the cardCode: Select all
on mouseUp local tKey put the short name of the target into tKey put the second char of tKey into field "Field1" end mouseUp
so you might want to add my "if...then..." clause.
Well, the script is pretty straighforward and not awkward at all (in LiveCode terms)Newbie4 wrote:There must be a less awkward way of doing this,...

Check these stacks, if not already done:Newbie4 wrote:(e.g. "target" is a new term to me. I have to read up on it and how to use it)
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Re: common buttons with different labels
Klaus wrote:Hi Newbie4,
Good, but this script will also execute when you click on the "naked" card (not on a button!)Newbie4 wrote:This worked:
I named the buttons - "b1", "b1", "ba", "bb", etc and used the following script on the cardCode: Select all
on mouseUp local tKey put the short name of the target into tKey put the second char of tKey into field "Field1" end mouseUp
so you might want to add my "if...then..." clause.
What would I check for? Individual buttons? any buttons? not buttons? card?
Well, the script is pretty straighforward and not awkward at all (in LiveCode terms)Newbie4 wrote:There must be a less awkward way of doing this,...![]()
It would be nice to use the label (the number on the button) instead of picking the off the number from the name. That is what I was thinking of
Check these stacks, if not already done:Newbie4 wrote:(e.g. "target" is a new term to me. I have to read up on it and how to use it)
http://www.runrev.com/developers/lesson ... nferences/
Thank you
Best
Klaus
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: common buttons with different labels
Hi Newbie4,
You want to check if the user really has clicked on a BUTTON and nothing else! No?
I had the feeling that you only want to execute your script when the user clicks a BUTTON...
You can put whatever you want into the buttons LABEL, but not into the NAME!
LABEL <> NAME!
These two are different:
LABEL is what you and the user see on screen, NAME is what you address the object with in your script!
So NAME your buttons as you already did but add somehting else as the LABEL of your buttons!
Then you can query the LABEL and do whatever you want woith it!
Best
Klaus
Please check my first post!Newbie4 wrote:What would I check for? Individual buttons? any buttons? not buttons? card?
You want to check if the user really has clicked on a BUTTON and nothing else! No?
I had the feeling that you only want to execute your script when the user clicks a BUTTON...
You CAN!Newbie4 wrote:It would be nice to use the label (the number on the button) instead of picking the off the number from the name. That is what I was thinking of
You can put whatever you want into the buttons LABEL, but not into the NAME!
LABEL <> NAME!
These two are different:
LABEL is what you and the user see on screen, NAME is what you address the object with in your script!
So NAME your buttons as you already did but add somehting else as the LABEL of your buttons!
Then you can query the LABEL and do whatever you want woith it!
Code: Select all
on mouseup
if word 1 of the target = "button" then
put the label of the target into fld "whatever"
## or whatever...
end if
end mouseup
Klaus
Re: common buttons with different labels
Thanks, your posts have really helped me to understand it all.
I was trying to do that but I did not know how to reference the label of the button that was pressed
e.g.
in the card script:
on mouseUp
put the label of the button ???? into the field "Field1"
end mouseUp
I did not know how to tell which button was pressed. The keyword "target" solves that
I understand now.
Thanks again.
I was trying to do that but I did not know how to reference the label of the button that was pressed
e.g.
in the card script:
on mouseUp
put the label of the button ???? into the field "Field1"
end mouseUp
I did not know how to tell which button was pressed. The keyword "target" solves that
I understand now.
Thanks again.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: common buttons with different labels
Hio Newbie4,
glad I could help.
And now you also understand my "if... then..." clause, I hope?
Best
Klaus
glad I could help.
And now you also understand my "if... then..." clause, I hope?

Best
Klaus