button to change menu selectedtext

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

button to change menu selectedtext

Post by ittarter » Fri Oct 02, 2015 6:00 pm

Hi guys,

Quick question. I want to be able to advance through the choices of a menu with a button, causing the selectedtext of the menu to change.

I tried

Code: Select all

put line (lineoffset(selectedtext of btn "menu",btn "menu") + 1) of btn "menu" into selectedtext of btn "menu"
but that didn't work, not sure why, it was a bit of a shot in the dark anyway :) but I thought I could search the text of the button for the current selectedtext, then add 1 to the line number of set that as the new selectedtext of the button. Maybe it would work with a slight change or maybe there's a better way to do this...

Any suggestions?

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: button to change menu selectedtext

Post by SparkOut » Fri Oct 02, 2015 6:16 pm

Look up "menuHistory" in the dictionary.

You probably want to

Code: Select all

put the menuHistory of button "Menu" into tMenu
set the menuHistory of button "Menu" to tMenu + 1
but if you want something else, a bit of explanation would be good :)

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: button to change menu selectedtext

Post by ittarter » Sat Oct 03, 2015 1:56 am

That appears to work, thank you!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: button to change menu selectedtext

Post by dunbarx » Sat Oct 03, 2015 2:32 am

Hi.

What happens when you get to the bottom?

Craig Newman
Last edited by dunbarx on Sat Oct 03, 2015 4:45 am, edited 1 time in total.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: button to change menu selectedtext

Post by SparkOut » Sat Oct 03, 2015 4:27 am

It's magic :)

Seriously though, it is a good point Craig raises. It is important to ensure your scripts change properties to valid values, not every aspect is going to be as forgiving as the menuHistory.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: button to change menu selectedtext

Post by dunbarx » Sat Oct 03, 2015 4:47 am

So, ittarter, do you see what I meant? I mean, what Sparkout meant?

We mean what we meant.

Craig

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: button to change menu selectedtext

Post by ittarter » Mon Oct 05, 2015 8:18 am

Yes, that was part of my initial test. Nothing happens past the last button option -- it doesn't cycle back to the top.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: button to change menu selectedtext

Post by SparkOut » Mon Oct 05, 2015 8:30 am

Yes, but the point is, you can't rely on everything working that way automagically. It is perfectly possible to set values of certain properties out of a safe range and have crashes or errors. This works, but remember generally to ensure the settings are validated. What if you had 5 menu items and setting the menuHistory to 6 gave a menuPick message with an empty choice? Other handlers may fail. So as long as you remember that input validation is generally important, you can leave the menuHistory to worry about that here.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: button to change menu selectedtext

Post by dunbarx » Mon Oct 05, 2015 2:46 pm

So.

Do you intend to simply ignore excessive values of the menuHistory, or, say, do you want to recycle back to the top? Or maybe present a dialog?

To leave it alone will make the user feel that something is not working correctly.

Craig

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: button to change menu selectedtext

Post by SparkOut » Mon Oct 05, 2015 9:29 pm

Or disable the button to advance the menuHistory when at the last (or first, if going upwards) menu item?

*high five Craig*

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: button to change menu selectedtext

Post by SparkOut » Mon Oct 05, 2015 9:31 pm

Sorry ittarter, getting flippant now. But hopefully you see that valid inputs make the user experience better.

Post Reply