Page 1 of 2
Set The Menu Items of an Option Menu (script)
Posted: Wed Feb 29, 2012 11:46 am
by Nakia
Hi,
I have an option Menu which I would like to have its Menu Items set by an external source ( a text file) on openCard.
I cant seem to find any where an option to be able to script adding Menu Items to an option Menu.
Have I over looked something very simple in the dictionary??
Thanks in advanced..
Kia
Re: Set The Menu Items of an Option Menu (script)
Posted: Wed Feb 29, 2012 11:54 am
by Klaus
Hi Kia,
you want to modify "the text of btn XYZ".
Which is... well... just text
you can e.g.:
...
set the text of btn "your menu button here" to tVariableWithText
...
put "A new menu item" into line 2 of btn XYZ
...
put "another new menuitem" after last line of btn XYZ
...
etc...
Please do also check these great resources where you will find this and much more
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Re: Set The Menu Items of an Option Menu (script)
Posted: Wed Feb 29, 2012 12:08 pm
by Nakia
Klaus wrote:Hi Kia,
you want to modify "the text of btn XYZ".
Which is... well... just text
you can e.g.:
...
set the text of btn "your menu button here" to tVariableWithText
...
put "A new menu item" into line 2 of btn XYZ
...
put "another new menuitem" after last line of btn XYZ
...
etc...
Please do also check these great resources where you will find this and much more
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Thanks so much,
Sorry for my ignorance, I am only new to LiveCode and sometimes struggle with basic tasks.
I was very close with my code, only error I was trying to set.
Thanks again so much...
Re: Set The Menu Items of an Option Menu (script)
Posted: Wed Feb 29, 2012 12:11 pm
by Nakia
Nakia wrote:Klaus wrote:Hi Kia,
you want to modify "the text of btn XYZ".
Which is... well... just text
you can e.g.:
...
set the text of btn "your menu button here" to tVariableWithText
...
put "A new menu item" into line 2 of btn XYZ
...
put "another new menuitem" after last line of btn XYZ
...
etc...
Please do also check these great resources where you will find this and much more
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Thanks so much,
Sorry for my ignorance, I am only new to LiveCode and sometimes struggle with basic tasks.
I was very close with my code, only error I was trying to set.
Thanks again so much...
sorry, last dumb question..
how can I retrieve current number of lines in button?
Re: Set The Menu Items of an Option Menu (script)
Posted: Wed Feb 29, 2012 2:45 pm
by Klaus
Hi Kia,
no need to excuse, LiveCode HAS a steep learning curve!
As I said, the "content" of a menubutton is just text so you can:
...
put the number of lines of the text of btn "XYZ" into tNumberOfMenuLines
...
Best
Klaus
Re: Set The Menu Items of an Option Menu (script)
Posted: Wed Feb 29, 2012 3:09 pm
by dunbarx
Kla.
As Klaus said.
It hardly matters, but you can write this in two ways:
answer the number of lines of button "yourButton"
answer the number of lines of the text of button "yourButton"
Spend just a second thinking about both. The first calls a function, the second calls a function based on a property. This is what I want you to see.
Flexibility is one of the most endearing things about LiveCode. There are usually a dozen ways to do the same thing, all from the same toolbox.
Re: Set The Menu Items of an Option Menu (script)
Posted: Thu Mar 01, 2012 5:40 am
by kdjanz
OK Craig - you have another newbie thinking. What are the tradeoffs between the two? Why would you want to use one or the other given that they have the same result? Does it take longer to fetch the property explicitly or is the engine doing it for you anyway in the short form?
Thanks
Kelly
Re: Set The Menu Items of an Option Menu (script)
Posted: Thu Mar 01, 2012 2:57 pm
by dunbarx
No difference in functionality. Just an example of flexibility, in that the myriad tools available can be used in many ways.
I would not have used the longer one, just because it takes more time to type; Klaus, who knows what he is talking about, would not either, unless that is just his style and way of thinking, which is perfectly legitimate.
Can you write a simple handler to answer your other question, to find out how much more efficient one version might be that the other?
That is what the LiveCode experience is all about, playing with tools and ideas.
Consider this homework.
Craig Newman
Re: Set The Menu Items of an Option Menu (script)
Posted: Fri Mar 02, 2012 7:04 am
by Nakia
Okay, another question for you guys..
I am trying to retrieve details from a button on a card (number of lines) but I need to do it from the Stack Script as I need to pass it around to multiple cards
below is what i would use if it is was on the card script but how do I add a reference to the card?
--put the number of lines of text of button "PilotID" into tPilotList
Re: Set The Menu Items of an Option Menu (script)
Posted: Fri Mar 02, 2012 7:05 am
by kdjanz
I've read Richard Gaskin's discussion of benchmarking, so I COULD set up a function that ran both lines 10,000 or 100,000 times and compared the milliseconds, but I'm not THAT interested since my option lists (and anything with variables in memory) are virtually instantaneous in LC by my standards - I'm never waiting for the language with anything I've done so far.
My question was more in the direction of form and style - I like what I see from Klaus and Bernd in the examples they give here, but that could be because they are keeping it simple for the newbies. LC will never get as cryptic as Forth, but some of it makes me take out a pencil and paper to track my way through the logic and different functions.
Cheers
Kelly
Re: Set The Menu Items of an Option Menu (script)
Posted: Fri Mar 02, 2012 7:28 am
by Nakia
never mind
--put the number of lines of text of button "PilotID" of card "ScoreCard" into tPilotList
Geez, I may be embarrassing myself

Re: Set The Menu Items of an Option Menu (script)
Posted: Fri Mar 02, 2012 1:19 pm
by Klaus
Come on Kia, don't be so hard to yourself
Yes, if you add a "descriptor" you can access all objects on all cards in all stacks.
...
put fld "xyz" of cd "zw" of stack "abc" into tText
...
If not LiveCode assumes you are refering to object on the current card and gives an error if they are not present.
Best
Klaus
Re: Set The Menu Items of an Option Menu (script)
Posted: Sat Mar 03, 2012 11:00 pm
by Nakia
another question,
I have this on a field script
---
on mouseUp
put the clickline into tSelectedPilot
put word 2 of tSelectedPilot into tSelectedLine
end mouseUp
---
How do I pass tSelectedLine to the stack script? I can see the Variable is populating on the field script but wont pass on any further, even to the card?? do I need to do a pass?
Re: Set The Menu Items of an Option Menu (script)
Posted: Sun Mar 04, 2012 7:20 am
by dunbarx
What will happen to it in the stack script?
If there is a a handler there, you can pass the number as a parameter. As you wrote:
on mouseUp
put the clickline into tSelectedPilot
put word 2 of tSelectedPilot into tSelectedLine
workWithThatLine tSelectedLine
end mouseUp
and then, in the stack script:
on workWithThatLine tLine
answer tLine --or whatever you need
end workWithThatLine
Alternatively, you can set a custom property of the field itself:
on mouseUp
set the lastLineClicked of me to word 2 of the clickLine
end mouseUp
And then at any time retreive that property:
And there are many other ways to do this.
Craig Newman
Re: Set The Menu Items of an Option Menu (script)
Posted: Sun Mar 04, 2012 7:42 am
by Nakia
Further information...
I have a scrolling list field in card "SetupMode" called "Pilots"
I also have a button on that card which I want act as a delete button which will delete the selected line of field "Pilots" when I press it..
So it needs to ,
1: check that a line is highlighted in field "Pilots"
2: delete that line from field "Pilots"