Page 1 of 1
button to change menu selectedtext
Posted: Fri Oct 02, 2015 6:00 pm
by ittarter
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?
Re: button to change menu selectedtext
Posted: Fri Oct 02, 2015 6:16 pm
by SparkOut
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

Re: button to change menu selectedtext
Posted: Sat Oct 03, 2015 1:56 am
by ittarter
That appears to work, thank you!
Re: button to change menu selectedtext
Posted: Sat Oct 03, 2015 2:32 am
by dunbarx
Hi.
What happens when you get to the bottom?
Craig Newman
Re: button to change menu selectedtext
Posted: Sat Oct 03, 2015 4:27 am
by SparkOut
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.
Re: button to change menu selectedtext
Posted: Sat Oct 03, 2015 4:47 am
by dunbarx
So, ittarter, do you see what I meant? I mean, what Sparkout meant?
We mean what we meant.
Craig
Re: button to change menu selectedtext
Posted: Mon Oct 05, 2015 8:18 am
by ittarter
Yes, that was part of my initial test. Nothing happens past the last button option -- it doesn't cycle back to the top.
Re: button to change menu selectedtext
Posted: Mon Oct 05, 2015 8:30 am
by SparkOut
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.
Re: button to change menu selectedtext
Posted: Mon Oct 05, 2015 2:46 pm
by dunbarx
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
Re: button to change menu selectedtext
Posted: Mon Oct 05, 2015 9:29 pm
by SparkOut
Or disable the button to advance the menuHistory when at the last (or first, if going upwards) menu item?
*high five Craig*
Re: button to change menu selectedtext
Posted: Mon Oct 05, 2015 9:31 pm
by SparkOut
Sorry ittarter, getting flippant now. But hopefully you see that valid inputs make the user experience better.