Page 1 of 1
Change Button Label
Posted: Wed Mar 21, 2012 8:23 pm
by HJay
Hi
Is it possible to change a button lable when the button is clicked on? so if it was called 1 and when it was clicked on is was then changed to another random number.
I tried to search the forum but it wouldn't let me as the words where to common?
Thanks in advance

Re: Change Button Label
Posted: Wed Mar 21, 2012 8:28 pm
by Klaus
Hi HJay,
you are almost there
Code: Select all
on mouseup
set the label of ME to "New label text here..."
## or to whatever to you like.
ernd if
Hint:
Please do not NAME buttons with numbers!
Name them "button1" if necessary, but NOT 1 or 2 etc...
But you can set the LABEL to whatever you like!
Ah, and welcome to the forum
Did you see these great learning stacks over here?
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Re: Change Button Label
Posted: Wed Mar 21, 2012 10:24 pm
by HJay
Hi Klaus
Thank you for your speedy responce. I am a complete beginner as you may have already guessed

I am using the free trial at the moment. I have repeated watched and tried to replicate the tutorials for the task list app thingy from the nice scottish lady. I have printed out and poured over the user guide. I have searched youtube for other video tutorials. I have made the 3 5 7 game thingy. I have studied user samples which have overwhelmed me somewhat. I have learned a bit and made my head hurt a lot

I have been unable to find a tutorial along the line of what I am trying to do though. So with 12 days left of my trial in which to find out if LiveCode will be able to do what I need I have started asking questions. Hopefully my questions will not be too dull

I hadn't found the link to the learning stacks so that was useful thank you.
I managed to get your code to work

I didn't know you could use ME so have learned something else new.
What I am actually trying to do is make a stack that will display a number and two buttons below, ButtonL and ButtonR. I want both buttons to display numbers, one that matches the sample number above. When a pupil clicks on the hopefully correct button I want another matching number problem to be be displayed.
What I think I should do is make the buttons variables and get the data from a list on another card. I think I will have to think a bit more about chunks at this point. Is this the direction to go in or am I stumbling down the wrong ally.
Any help very much appreaciated
HJay
Re: Change Button Label
Posted: Wed Mar 21, 2012 10:36 pm
by mwieder
Setting the *name* of a button and setting the *label* of a button are different things. The name is how you will refer to the button in your script. You can easily display numbers in the buttons by setting their labels. But it's a bad idea to set the name itself to a number. Name the button once when you're designing the screen and then don't change it after that.
The label is what gets displayed as the button's text on the screen:
Code: Select all
set the label of button "ButtonL" to 42
Code: Select all
put pi * 3 into tVariable
set the label of button "ButtonR" to tVariable
Welcome to LiveCode and keep asking questions.

Re: Change Button Label
Posted: Thu Mar 22, 2012 9:14 am
by HJay
Thanks for that I am moving forward
Just for the record I would just like to point out that I have never committed the heinous crime of giving a button a name that was a number. This was purely by luck though and I now solemnly swear never in future to name a button by a number.
I have a card with 2 buttons on in named ‘ButtonL’ and ‘ButtonR’
I have this code on the card (because at a later date I want both buttons to change when I click on either of them, is this the right thing to do?):-
Code: Select all
on mouseUp
put any item of "0,1,2,3,4,5,6,7,8,9" into tVariable
set the label of button "ButtonR" to tVariable
end mouseUp
and when I click ‘ButtonR’ sure enough I get a random single digit number

…
...but when I click on ’ButtonL’ which I have labelled ‘Left’ it changes the label on ‘ButtonR’
which is confusing me as as far I can see I haven’t told ‘ButtonL’ to do anything other than label itself ‘Left’. Why is this happening?
Re: Change Button Label
Posted: Thu Mar 22, 2012 5:47 pm
by mwieder
You'll want to have a look at Richard Gaskin's article on the message path.
http://www.fourthworld.com/embassy/arti ... _path.html
But basically, your mouseUp handler in the card is being triggered by the "ButtonL" button probably because there is no mouseUp handler in that button. So lacking a handler there, the card is the next place to check. And bingo! there's a mouseUp handler to execute. If you change your code in the stack script to read
Code: Select all
on mouseUp
put any item of "0,1,2,3,4,5,6,7,8,9" into tVariable
set the label of button "ButtonR" to tVariable
put any item of "0,1,2,3,4,5,6,7,8,9" into tVariable
set the label of button "ButtonL" to tVariable
end mouseUp
you should have what you want.
Re: Change Button Label
Posted: Thu Mar 22, 2012 6:37 pm
by HJay
Thank you and thank you for the link.
I had come across the message path in the live code tutorials, which is why I thought that I should put the code on the card rather than the buttons?
I still don’t see why code that only tells ButtonR to do something should change ButtonL though. I did a test putting some code onto ButtonL and it stoped changing when ButtonR was pressed, as you said it would. Does this mean that every button I use has to have code associated with it otherwise it may do something I have not asked it to do?
I am now off to learn some more about chunks and arrays. Thank you so much for pointing me in the right direction.

Re: Change Button Label
Posted: Thu Mar 22, 2012 6:47 pm
by Klaus
Hi HJay,
yes, if you have 10 buttons on your card and none of them does have a "mouseup" script
but you have a "mouseup" in the script of the CARD, then ALL buttons will execute
THAT "mouseup" script of the card.
This is what the "message hierarchie" is all about
In your case (only two buttons) you could still use the mouseup in the card, but then CHECK
which of your two buttons has been clicked and act accordingly:
Code: Select all
on mouseUp
put any item of "0,1,2,3,4,5,6,7,8,9" into tVariable
# no we use "THE TARGET" to see what button has been clicked
put the short name of the target into tClickedButtonName
## ButtonR has been cliked, so change the label of the other button:
if tClickedButtonName = "ButtonR" then
set the label of button "ButtonL" to tVariable
else
## and vice versa :-)
set the label of button "ButtonR" to tVariable
end if
end mouseUp
Best
Klaus
Re: Change Button Label
Posted: Thu Mar 22, 2012 7:09 pm
by mwieder
This is what the "message hierarchie" is all about
Yes, and this is part of what makes LiveCode so powerful.
Look - it really takes about six weeks for all this to sink in, so don't worry about trying to make sense of everything all at once.
You're off to a great start so far.
Re: Change Button Label
Posted: Tue Mar 27, 2012 5:55 pm
by HJay
Thank you both for your helpful replies, I do feel like I'm swimming through treacle at the moment but will keep going

Re: Change Button Label
Posted: Tue Mar 27, 2012 5:57 pm
by Klaus
HJay wrote:Thank you both for your helpful replies, I do feel like I'm swimming through treacle at the moment but will keep going

Yeah, bravo, don't give up, you won't regret!
And thank you for teaching me a new english word: treacle
Best
Klaus
Re: Change Button Label
Posted: Mon Apr 02, 2012 10:08 am
by HJay
lol is there no treacle in Germany? Or is it just called something else?
I am putting together some flashcards to aid my learning.
Would you mind adding a few Q. and A.'s you think should be learned at the beginning? I need to get about sixty before I can start doing them.
http://forums.runrev.com/viewtopic.php? ... 392#p54392
Thanks in advance
HJay
Re: Change Button Label
Posted: Mon Apr 02, 2012 12:07 pm
by Klaus
Hi HJay,
HJay wrote:lol is there no treacle in Germany? Or is it just called something else?
???
Of course we have "Rübenkraut" here in germany, but I did not know the english word for it
until your post forced me to look it up in a dictionary!
OK, for your Q&A:
The german word for "treacle" is ______________
Best
Klaus
Re: Change Button Label
Posted: Mon Apr 02, 2012 1:43 pm
by HJay

I thought kraut meant cabbage, well you learn something new everday
HJay
Re: Change Button Label
Posted: Mon Apr 02, 2012 2:28 pm
by Klaus
Hi HJay,
well "cabbage" is actually "Kohl" in german, just like the ex-chancellor
Best
Klaus