Why does this not work? (radio button group values)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Why does this not work? (radio button group values)
Simple stack consisting of one card with two groups of radio buttons and a pushbutton. The idea is that the user selects something from each radio button group and then presses the button. As a test, I am just answering the two selections in the pushbutton script - well, I am trying to...
I have two global variables in the main stack ("BritShip" and "GermShip") in which I am trying to store the selections from two groups of radio buttons for use throughout the rest of the app when it is done. Everything seems to work fine if I dump the selections to fields and then read the fields in the button script but if I just use the variables it fails.
For the card:
On OpenStack
Global BritShip, GermShip
--This should work with Local, correct???
end OpenStack
For the first radio button group:
On Mouseup
put the short name of target into BritShip
End Mouseup
(and similar for the second radio button group, only the variable is GermShip)
The button script:
on mouseUp
answer BritShip && GermShip with "Okay"
end mouseUp
What I am getting is "BritShip GermShip".
What I want is (for example) "Hood Gneisenau". I can only seem to make this work if I add fields to the card and change the radio button group scripts to "Put the short name of target into BritShipField" and then add "Put the text of field BritShipField into BritShip" (and one for the German Ship) before the answer line in the button script.
What simple thing am I missing here?
Also, how do I "force" each group to have a specific radio button selected when the stack is opened each time?
Thanks.
I have two global variables in the main stack ("BritShip" and "GermShip") in which I am trying to store the selections from two groups of radio buttons for use throughout the rest of the app when it is done. Everything seems to work fine if I dump the selections to fields and then read the fields in the button script but if I just use the variables it fails.
For the card:
On OpenStack
Global BritShip, GermShip
--This should work with Local, correct???
end OpenStack
For the first radio button group:
On Mouseup
put the short name of target into BritShip
End Mouseup
(and similar for the second radio button group, only the variable is GermShip)
The button script:
on mouseUp
answer BritShip && GermShip with "Okay"
end mouseUp
What I am getting is "BritShip GermShip".
What I want is (for example) "Hood Gneisenau". I can only seem to make this work if I add fields to the card and change the radio button group scripts to "Put the short name of target into BritShipField" and then add "Put the text of field BritShipField into BritShip" (and one for the German Ship) before the answer line in the button script.
What simple thing am I missing here?
Also, how do I "force" each group to have a specific radio button selected when the stack is opened each time?
Thanks.
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Why does this not work? (radio button group values)
Global variables must be declared within each handler that uses them, or at the top of a script outside of any handlers to be used by any handlers in that script.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Why does this not work? (radio button group values)
Aaah, I see now. I am used to Global variables being declared once and then used anywhere. New behaviors can be hard for old dogs to learn. Thanks (much) for the heads up.
Trying to learn some more here, why does the button script:
on mouseUp
put the short name of BritishGroup into BritShip
put the short name of GermGroup into GermShip
answer BritShip && GermShip with "Okay"
end mouseUp
Give me a chunk error at BritishGroup? How do I refer to the selected radio button within a group? (yes, I am just learning here - I will be using the global variables throughout the stack.) This will come in handy later.
Trying to learn some more here, why does the button script:
on mouseUp
put the short name of BritishGroup into BritShip
put the short name of GermGroup into GermShip
answer BritShip && GermShip with "Okay"
end mouseUp
Give me a chunk error at BritishGroup? How do I refer to the selected radio button within a group? (yes, I am just learning here - I will be using the global variables throughout the stack.) This will come in handy later.
Re: Why does this not work? (radio button group values)
Hi.
Just takes a little time to shift gears.
The "name" of an object is a property of that object, and could reference, say, a field, graphic or button. But a variable, no matter what sort or variable, has no such property. LC is tripping on that, and throwing an error. If you think about it, the "name" of the variable is just that, its name, but is referenced directly:
Put "45" into yourVariable
put yourVariable into fld "yourField"
Now when you wrote: put the short name of BritishGroup into BritShip
is "BritishGroup" a variable, or is it an object reference? If a variable, you run afoul of the above discussion. If an object, you need to say so:
put field "BritishGroup" into britShip
On another note, you might want to learn a bit about custom properties. These are like globals, but survive between sessions, and need be declared only once from any source. I use almost no globals at all anymore, preferring these more permanent and far more powerful entities. They can hold much more that just data.
Craig Newman
Just takes a little time to shift gears.
The "name" of an object is a property of that object, and could reference, say, a field, graphic or button. But a variable, no matter what sort or variable, has no such property. LC is tripping on that, and throwing an error. If you think about it, the "name" of the variable is just that, its name, but is referenced directly:
Put "45" into yourVariable
put yourVariable into fld "yourField"
Now when you wrote: put the short name of BritishGroup into BritShip
is "BritishGroup" a variable, or is it an object reference? If a variable, you run afoul of the above discussion. If an object, you need to say so:
put field "BritishGroup" into britShip
On another note, you might want to learn a bit about custom properties. These are like globals, but survive between sessions, and need be declared only once from any source. I use almost no globals at all anymore, preferring these more permanent and far more powerful entities. They can hold much more that just data.
Craig Newman
Re: Why does this not work? (radio button group values)
Thanks for the tip about custom properties, they sound just like one of the things I am looking for! I have used something similar in other environments, and for roughly the same purposes. The idea of a permanent variable (that survives restarts) is a good one that saves lots of time - probably comes from the mobile world???
BritishGroup is a group of radio buttons. It is not a field and: " put the value of the group "BritishGroup" into BritShip" is an error.
Trying to clear up my complete bafflement, I have a group of radio buttons called rbgroup. How do I refer to the text of the selected radio button programmatically? The expression "answer the text of the group "regroup" with "Yes" " in a pushbutton is an error waiting to happen. What would the correct syntax be?
How do I set the value of regroup programmatically?
Thanks again. I really appreciate the help.
BritishGroup is a group of radio buttons. It is not a field and: " put the value of the group "BritishGroup" into BritShip" is an error.
Trying to clear up my complete bafflement, I have a group of radio buttons called rbgroup. How do I refer to the text of the selected radio button programmatically? The expression "answer the text of the group "regroup" with "Yes" " in a pushbutton is an error waiting to happen. What would the correct syntax be?
How do I set the value of regroup programmatically?
Thanks again. I really appreciate the help.
Re: Why does this not work? (radio button group values)
Experiment, experiment, experiment.
New card. Make three buttons, and name them all. Put something into each one (buttons are containers, like fields, and can contain text). Group them. Click on one of them. In another button somewhere:
Read the dictionary. Write back.
Craig
New card. Make three buttons, and name them all. Put something into each one (buttons are containers, like fields, and can contain text). Group them. Click on one of them. In another button somewhere:
Code: Select all
on mouseup
answer the hilitedButtonName of grp 1 && btn the hilitedButtonName of grp 1
end mouseup
Craig
Re: Why does this not work? (radio button group values) SOLV
Thank you very much!
Did you know that "hilitedButtonName" does not appear in the users guide? That is probably how I missed it. It does appear in the dictionary under the set command. Now how did I miss that? Well, I was looking at put and get.
Thank goodness for the forums!!!
Did you know that "hilitedButtonName" does not appear in the users guide? That is probably how I missed it. It does appear in the dictionary under the set command. Now how did I miss that? Well, I was looking at put and get.
Thank goodness for the forums!!!
Re: Why does this not work? (radio button group values)
Craig,
I figured out most of what I was looking for and I think what you were trying to show me. Many thanks.
One question remains - what is the "btn" for in your example? So far, all I get is that it makes that part "null".
I figured out most of what I was looking for and I think what you were trying to show me. Many thanks.
One question remains - what is the "btn" for in your example? So far, all I get is that it makes that part "null".
Re: Why does this not work? (radio button group values)
Hi.
Did you put some text into those buttons? No eh? Well, do so now. I was trying to point out the various ways to reference objects, their properties and their contents.
Write back...
Craig
Did you put some text into those buttons? No eh? Well, do so now. I was trying to point out the various ways to reference objects, their properties and their contents.
Write back...
Craig
Re: Why does this not work? (radio button group values)
By "put some text into those buttons" did you mean a label? If so, then yes I did. All that happened when I pressed the pushbutton was that the NAME of the hilighted radio button was "answered". I split the answer into two answers and the part with "btn" answered as blank. I have messed around with various things and as near as I can tell I missed the point. 'btn' appears to not be a valid command as far as I can tell - it comes up blank in the dictionary and there is no reference to it in the users guide. inserting it into code just renders the 'answer' as blank.
I appreciate that you are truing to help, but I think I failed this particular part of the lesson. I did learn that the Mavericks autocorrect REALLY does not 'btn' and that great care is required for it not to be 'btw'.
I HAVE learned:
How to set the value of a radio button in group to the value I want.
How to get the NAME of a selected radio button.
How to get the label (value) of a selected radio button.
Some things about LiveCode that I am not particularly fond of (referring to the new and somewhat constrained definition of local and global).
That Custom Properties are persistent but only valid for the object they are used with. This is useful, but not a truly global variable. Well, it is, but not really. I still have to explore this some more!
The LC documentation is not quite at a level of usefulness that I want it to be - Did you know that Repeat With is defined, but not Repeat For?
I am not used to using forums for learning syntax - I am used to using documentation. The times they have changed.
Lots of things to like about LC, but that a complete paradigm shift is required in my coding. The biggest problem I am going to have is to stop using '=' when I mean 'put'!!!
I appreciate that you are truing to help, but I think I failed this particular part of the lesson. I did learn that the Mavericks autocorrect REALLY does not 'btn' and that great care is required for it not to be 'btw'.
I HAVE learned:
How to set the value of a radio button in group to the value I want.
How to get the NAME of a selected radio button.
How to get the label (value) of a selected radio button.
Some things about LiveCode that I am not particularly fond of (referring to the new and somewhat constrained definition of local and global).
That Custom Properties are persistent but only valid for the object they are used with. This is useful, but not a truly global variable. Well, it is, but not really. I still have to explore this some more!
The LC documentation is not quite at a level of usefulness that I want it to be - Did you know that Repeat With is defined, but not Repeat For?
I am not used to using forums for learning syntax - I am used to using documentation. The times they have changed.
Lots of things to like about LC, but that a complete paradigm shift is required in my coding. The biggest problem I am going to have is to stop using '=' when I mean 'put'!!!
Re: Why does this not work? (radio button group values)
Hi Martimer,
I think this was just a typo, since that does not mean anything
And custom properties need a while to get used to, but then you do not wnat to miss them anymore
Another advantage of CPs is, that unlike variables, they (can/will) get saved with the stack!
Practical example:
You have a button that moves to somewhere on your card.
At some point you want to "reset" it to its original (saved) location.
Then you can hardcode:
...
set the loc of btn "blabla" to 100,200
...
But using a cp of that button is much more effective in my opinion!
Create this cp for that button, set its value to 100,200 in the inspector and then you can:
...
set the loc of btn "blabla" to the cStoredLocation of btn "blablabla"
...
No need to change the script etc...
Best
Klaus
Code: Select all
... && btn the hilitedButtonName of grp 1...

And custom properties need a while to get used to, but then you do not wnat to miss them anymore

Another advantage of CPs is, that unlike variables, they (can/will) get saved with the stack!
Practical example:
You have a button that moves to somewhere on your card.
At some point you want to "reset" it to its original (saved) location.
Then you can hardcode:
...
set the loc of btn "blabla" to 100,200
...
But using a cp of that button is much more effective in my opinion!
Create this cp for that button, set its value to 100,200 in the inspector and then you can:
...
set the loc of btn "blabla" to the cStoredLocation of btn "blablabla"
...
No need to change the script etc...
Best
Klaus
Re: Why does this not work? (radio button group values)
Typo? No.
I asked you to
put "xyz" into button 1
put "ABC" into button 2
put "123" into button 3
Buttons are containers, and they can hold data. This has nothing to do with labels. Now run the handler again.
Klaus. My first time for this, I think...
Craig
I asked you to
When I said "put something into each one" I wanted you to:New card. Make three buttons, and name them all. Put something into each one (buttons are containers, like fields, and can contain text). Group them. Click on one of them. In another button somewhere:
put "xyz" into button 1
put "ABC" into button 2
put "123" into button 3
Buttons are containers, and they can hold data. This has nothing to do with labels. Now run the handler again.
Klaus. My first time for this, I think...

Craig
Re: Why does this not work? (radio button group values)
Cool, and interesting.
When working with radio buttons I am used to just working with the displayed label, but I will try to remember this for the future.
What was your "intent" with the second part of that answer statement? What was "btn" supposed to be? I would hate to miss an opportunity to learn.
Thanks.
When working with radio buttons I am used to just working with the displayed label, but I will try to remember this for the future.
What was your "intent" with the second part of that answer statement? What was "btn" supposed to be? I would hate to miss an opportunity to learn.
Thanks.
Re: Why does this not work? (radio button group values)
Hmmm.
"the hilitedButtonName" calls a property, and gives the name of the button, say, for example, "b1"
But "button the hilitedButtonName" resolves to: button "b1". Do you see that?
In this construction, the contents of the button, not its name, is returned. It should not shock you if you executed:
answer field "yourField"
and got the contents of that field, right? Well this works for any container, and buttons are containers. So if you put text into a button, just as you might put text into a field, you can get that text back with the same call. It is just that most users do not "see" a button as a container.
Whew.
Craig
"the hilitedButtonName" calls a property, and gives the name of the button, say, for example, "b1"
But "button the hilitedButtonName" resolves to: button "b1". Do you see that?
In this construction, the contents of the button, not its name, is returned. It should not shock you if you executed:
answer field "yourField"
and got the contents of that field, right? Well this works for any container, and buttons are containers. So if you put text into a button, just as you might put text into a field, you can get that text back with the same call. It is just that most users do not "see" a button as a container.
Whew.
Craig
Re: Why does this not work? (radio button group values)
I did not see any output for "button the hilitedButtonName of grp 1". It is a null.
I get the rest just fine. Using a button as a container is an interesting concept.
I get the rest just fine. Using a button as a container is an interesting concept.