|
Rebel Novice
Joined: 29 Oct 2007 Posts: 33
|
Posted: Tue Oct 30, 2007 10:44 pm
How do I use a trigger inside a #forall loop? |
I have a list of items :-
list "a|b|c|d"
and I want to process them, but each process takes 15-20 seconds - I can set up a trigger to detect "work completed" - but how do I use this in the #FORALL loop?
I need to slow down the loop somehow....
#FORALL @list {process %i ...wait for trigger?.... }
Or perhaps I'm not tackling this problem the right way?
Thanks for any advice |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Oct 30, 2007 11:50 pm |
I would use something like this:
#alarm "DoStuff" *20 {temp=%pop(@list);do whatever;#if (!%numitems(@list)) {#t- DoStuff}}
If you're only using the item in the list once during your "do whatever" part, remove the temp= command and just use %pop(@list) where you'd normally use %i. If you're using it more than once, leave the temp= in there and use @temp where you'd normally use %i.
You could also use a trigger in a similar manner with the pattern "Work completed" or whatever, but in that case you'll have to send the first command manually. You might find that sending the first command manually will help in this case, too. |
|
|
|
Rebel Novice
Joined: 29 Oct 2007 Posts: 33
|
Posted: Wed Oct 31, 2007 9:53 am |
Many thanks for prompt response. I would prefer to use a trigger to avoid un-neccessary delays so would it be :-
I am making progress...woo woo - apparently the %pop and %numitems require only the variable name - no "@" symbol
process %pop(list)
#trigger {work completed} {process %pop(list);#if(!%numitems(list))}
.....
ermmm what's the syntax to break out of the trigger when there are no items left in the list, I am still trying to process a null at the end ? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Oct 31, 2007 12:21 pm |
Sorry about the %pop not needing @ thing - I always forget that :(
You've missed off the all-important {#t- DoStuff} part at the end - it's part of the #if command. The #t- command disables a trigger with a given ID, so you need to give your trigger the ID "DoStuff" for it to work. Then the second command of your alias just does #t+ DoStuff instead of #trig {work completed} blah blah blah, to save you creating and erasing a trigger every time. If you simply must do it that way, you can have your alias create the trigger and then use #untrigger to delete it. |
|
|
|
Rebel Novice
Joined: 29 Oct 2007 Posts: 33
|
Posted: Wed Oct 31, 2007 3:22 pm |
Still making progress....hehe - I'm a bit of a perfectionist :) One last problem :-
After all the items have been processed, I still have one null entry being processed at the end, I've tried using
#if (%numitems(list)=1) #t- DoStuff
but still I have a null item being processed.
Any ideas? |
|
|
|
Rebel Novice
Joined: 29 Oct 2007 Posts: 33
|
Posted: Wed Oct 31, 2007 4:45 pm |
Heh - solved it - my mistake - %numitems requires the @list parameter - not list
Thanks again |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Oct 31, 2007 4:53 pm |
Don't forget the braces {} around the commands in the #if. The example you have there has #t- as the true-command and DoStuff as the false-command.
|
|
|
|
Rebel Novice
Joined: 29 Oct 2007 Posts: 33
|
Posted: Mon Nov 12, 2007 3:02 pm |
This is now working ok - but my current problem is that I want to do something else after the list has been processed - so I want to do something like
#trigger {work completed} {process %pop(list);#if(!%numitems(@list)){#t- DoStuff; wear item}}
However this causes me to wear the item before the 20-30 secs it takes to process each item -and the act of wearing it interrupts the process.
I've tried putting another trigger in there :-
#trigger {work completed} {process %pop(list);#if(!%numitems(@list)) {#t- DoStuff; #temp {completed} {wear item}}}
- but this still doesn't wait for the 20-30 secs - any advice appreciated |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Nov 12, 2007 3:22 pm |
Spaces are very important. Don't miss them out.
It's by design that the trigger is turned off when the last item begins processing - it stops the trigger trying to process when there's nothing on the list. You could change the trigger's script to something like this:
#if (%numitems(@list)=1) {#t- DoStuff}
#if (%numitems(@list)>0) {process %pop(list)} {wear item} |
|
|
|
Rebel Novice
Joined: 29 Oct 2007 Posts: 33
|
Posted: Mon Nov 12, 2007 4:02 pm |
Many thanks - I finally got it to work with
#if (%numitems(@list)=0) {#t- DoStuff}
#if (%numitems(@list)>0) {process %pop(list)} {wear item}
Your suggestion put me on the right track, but did not process the last item on the list - thanks again |
|
|
|
|
|