Set The Menu Items of an Option Menu (script)

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Set The Menu Items of an Option Menu (script)

Post by Nakia » Wed Feb 29, 2012 11:46 am

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

Klaus
Posts: 11268
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Set The Menu Items of an Option Menu (script)

Post by Klaus » Wed Feb 29, 2012 11:54 am

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 :D
http://www.runrev.com/developers/lesson ... nferences/


Best

Klaus

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Set The Menu Items of an Option Menu (script)

Post by Nakia » Wed Feb 29, 2012 12:08 pm

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 :D
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...

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Set The Menu Items of an Option Menu (script)

Post by Nakia » Wed Feb 29, 2012 12:11 pm

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 :D
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?

Klaus
Posts: 11268
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Set The Menu Items of an Option Menu (script)

Post by Klaus » Wed Feb 29, 2012 2:45 pm

Hi Kia,

no need to excuse, LiveCode HAS a steep learning curve! :D

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6229
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Set The Menu Items of an Option Menu (script)

Post by dunbarx » Wed Feb 29, 2012 3:09 pm

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.

kdjanz
Posts: 142
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Set The Menu Items of an Option Menu (script)

Post by kdjanz » Thu Mar 01, 2012 5:40 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6229
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Set The Menu Items of an Option Menu (script)

Post by dunbarx » Thu Mar 01, 2012 2:57 pm

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

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Set The Menu Items of an Option Menu (script)

Post by Nakia » Fri Mar 02, 2012 7:04 am

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

kdjanz
Posts: 142
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Set The Menu Items of an Option Menu (script)

Post by kdjanz » Fri Mar 02, 2012 7:05 am

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

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Set The Menu Items of an Option Menu (script)

Post by Nakia » Fri Mar 02, 2012 7:28 am

never mind
--put the number of lines of text of button "PilotID" of card "ScoreCard" into tPilotList

Geez, I may be embarrassing myself :oops:

Klaus
Posts: 11268
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Set The Menu Items of an Option Menu (script)

Post by Klaus » Fri Mar 02, 2012 1:19 pm

Come on Kia, don't be so hard to yourself :D

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

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Set The Menu Items of an Option Menu (script)

Post by Nakia » Sat Mar 03, 2012 11:00 pm

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?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6229
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Set The Menu Items of an Option Menu (script)

Post by dunbarx » Sun Mar 04, 2012 7:20 am

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

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Set The Menu Items of an Option Menu (script)

Post by Nakia » Sun Mar 04, 2012 7:42 am

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"

Post Reply

Return to “Talking LiveCode”