Concurrent actions
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Concurrent actions
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.
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.
Life is just a bowl of cherries.
Hi bjb007,
I think you are looking for something like this:
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:
Best,
Mark
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
Code: Select all
send "flash" to field "Your Field"
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Concurrent actions
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?
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?
Life is just a bowl of cherries.
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
wait 300 millisecs with messages
instead of a regular wait.
Hth,
Malte
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:
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
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
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Concurrent actions
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.
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.
Life is just a bowl of cherries.
Mark most likely has some function which evaluates to true if a number is even, for example like this:
Make sure not to put anything but a number into theCounter, most likely that was your problem with "if theCounter < 5".
Code: Select all
function even theNumber
if theNumber mod 2 = 0 then
return true
else
return false
end if
end even
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Code in a field
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?
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?
Life is just a bowl of cherries.