Setting the value of a button hilite in script
pete at mollysrevenge.com
Tue Dec 13 21:48:29 EST 2011
Thanks for the suggestions Phil. I'm attempting to put initial values into
all the controls on the card not just buttons. My code figures out what
type of control it's dealing with by looking at the first word of the
abbrev name, then the menumode and style if it's a button. Once it's
figured out what type of control it's dealing with, it issues a set for
the appropriate property or a put if it's field.
I've worked around the problem by using a do command to issue the
appropriate command instead of hard coding the command itself and that
works just fine.
I think this is just one of those weirdnesses that comes up every now and
again. In this case LC is treating everything as text even if it's a
reserved word, which I can kind of understand. Unfortunately, unlike the
sort command discussion that's been going on the last couple of days,
there's no simple keyword I can add to make it work correctly, hence the do
While we're at it, here's another oddity that always bugs me. The
"compiler" (the thing that runs when you click the apply button) can't
figure out the difference between "repeat for" and "repeat with". I'm
prone to using the wrong form just because I can never remember which is
which. I often write something like "repeat for x=1 to the number of
controls on this card". It should be "repeat with" but the error doesn't
get flagged until run time. Once again, not a big deal, but seems like
that should be detected as an error during the Apply process.
For no particular reason other than I'm an Englishman living in California
and completely off topic, I'm really missing the British pantomime
tradition at this time of the year. "OH YES I AM!!!"
On Tue, Dec 13, 2011 at 5:43 PM, Phil Davis <revdev at pdslabs.net> wrote:
> Hi Pete,
> I'm not always good at staying on-topic, but maybe some of this will
> On 12/13/11 2:50 PM, Pete wrote:
>> I wrote myself a script to set the initial values of controls on a card in
>> preOpenCard. It looks for a custom property name cInitialValue, then
>> initialises the control to the value of the custom property, depending on
>> that type of control (field, button, etc).
>> I set the value of cInitialValue for checkboxes or radio buttons to either
>> true or false. My code then is:
>> set the hilite of control x of this card to (the cInitialValue of control
>> of this card)
>> At run time, I get an error - value is not a boolean (true or false) near
> Couple of things:
> - since only buttons can have hilites, why not make your 'set' loop deal
> with buttons only? e.g. "set the hilite of btn x of ...."
> - an easy way to handle empty cprop hilite values (assuming empty = false)
> set the hilite of btn x of this card to (the cInitialValue of btn x of
> this card = true)
> Doing this will prevent runtime hilite-setting errors (though your hilites
> may still not be set to the correct values)
>> I'm suspecting this is because true and false are reserved words but the
>> set statement is treating them as literals (they are not in quotes in the
>> cprop though). However, the statement:
>> put (the cInitialValue of control x of this card) into control x of this
>> ...works just fine when the value of the cprop is the word empty, also a
>> reserved word.
> Right - buttons can contain text, so you can put empty or other text into
> them without an error.
>> I'm reduced to what looks like a nonsenical if statement that checks the
>> cprop for true or false and sets the hilite of the button to true or
>> Looks really weird!
> Wait until you get or set the text of an image! That always makes me
>> I've meddled enough for now...
> Phil Davis
> PDS Labs
> Professional Software Development
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
Molly's Revenge <http://www.mollysrevenge.com>
More information about the Use-livecode