Page 1 of 1
Concurrent actions
Posted: Wed Mar 19, 2008 1:27 am
by bjb007
I want to alert the user to certain conditions
by flashing the backgroundColor of a field.
As I've coded it everything else stops while
the field is flashing.
Can I let the script get on with other things
while the flashing goes on?
I have three fields and more than one might
need to flash at the same time.
Posted: Wed Mar 19, 2008 2:39 am
by Mark
Hi bjb007,
I think you are looking for something like this:
Code: Select all
on flash theCounter
if theCounter is empty then
put 1 into theCounter
else
add 1 to theCounter
end if
if even(theCounter) then
set the backColor of me to red
else if theCounter < 5 then
set the backColor of me to green
else
set the backColor of me to white
end if
if theCounter < 5 then
send "flash theCounter" to me in 1 sec
end if
end flash
If I didn't make a mistake, this script will make a field change colour a few times and eventually return to white. Simply put this into the script of a field and use the following to execute it:
Code: Select all
send "flash" to field "Your Field"
Best,
Mark
Concurrent actions
Posted: Wed Mar 19, 2008 6:40 am
by bjb007
Mark
I get the field to flash with code like this:
repeat with i = 1 to 5
set backgroundColor of field lbl1 to 255,255,255
wait for 300 milliseconds
set backgroundColor of field lbl1 to 255,125,125
wait for 300 milliseconds
end repeat
Problem is that while this is happening field 2 is
waiting to flash or field 3 or any combination of
two fields.
Is there a simpler method that coding for all
possible combinations so that if two or three
fields are in "flash" condition they flash at
the same time?
Posted: Wed Mar 19, 2008 10:03 am
by malte
You issue a wait command in your code. That is a blocking operation, so no messages come through and the engine halts at the wait command until the specified time is over. Depending on how you call the code snipped you posted here it might work to use
wait 300 millisecs with messages
instead of a regular wait.
Hth,
Malte
Posted: Wed Mar 19, 2008 10:59 am
by Mark
bjb007,
Any reason why you don't want to use the example I posted?
If really want to use wait with messages, you might do this:
Code: Select all
repeat with i = 1 to 5
set backgroundColor of field lbl1 to 255,255,255
set backgroundColor of field lbl1 to 255,125,125
wait for 300 milliseconds
end repeat
but your fields would flash simultaneously, which doesn't look as nifty as independently flashing fields. Also, you can't continue to execute your script. It is so much more elegant to send a flash command to a field and not to worry about it anymore while your script does other tasks.
Best,
Mark
Concurrent actions
Posted: Wed Mar 19, 2008 1:45 pm
by bjb007
Mark
Thanks for the nifty 'flash' code. I love it!
I didn't get the concept on first reading
but once I understood that the code went
into the field script.....I was away.
Works great except for the "if even(theCounter)..
which Rev doesn't like. I can't find "even" in
the docs so used a string of items.
Is there a way to use "if theCounter < 5 then"?
It gives the "double binary" error.
Now if I was really clever I might figure out
a way to have only one copy of the 'flash' code
instead of seven (and no doubt will be more).
There are so many places that code can be
put. Handy in this instance but trying to make
sense of someone else's stack can sometimes
be a pain.
Posted: Wed Mar 19, 2008 4:04 pm
by BvG
Mark most likely has some function which evaluates to true if a number is even, for example like this:
Code: Select all
function even theNumber
if theNumber mod 2 = 0 then
return true
else
return false
end if
end even
Make sure not to put anything but a number into theCounter, most likely that was your problem with "if theCounter < 5".
Code in a field
Posted: Thu Mar 20, 2008 12:07 am
by bjb007
Putting code into a field reminded me
of how sceptical I was the first time I
used a spreadsheet way back in the
days of Ashton-Tate.
Just didn't seem right, possible or
sensible then. It really was something
different. Wonder who came up with
that idea?