Run Sequences In Variable Order?


EA1

Recommended Posts

I have a series of valves that are each activated by a sequence call. I would like to create a simple way to re-order the valve sequences without creating a new script each time. Basically, I'd like to enter the numeric valve order somewhere on a control page, and have these values be used to call the correct sequence in the correct order. Any suggestions?

Thanks.

Link to comment
Share on other sites

Should be pretty easy if you name your sequences sequentially, say "Valve1", "Valve2", etc. Then, let's say you have a global string variable called "order". If you run this sequence, it will call those sequences inthat order:


for (private i = 0, i < getLength(order), i++)
try
execute("valve" + mid(order,i,1) + "()")
catch()
? strLastError // don't stop if there's a typo
endcatch
endfor

[/CODE]

Link to comment
Share on other sites

Thanks very much! This works as you said. 2 more questions, though: 1) for more than 9 valves, I could substitute letters for single digits and address an alphabet's worth of valves, but how would your code work if there was a 2 digit number for each valve sequence....e.g., up to valve99. 2) Is there a way to do something similar with string arrays, if the sequences are named without the same string format?

Link to comment
Share on other sites

There are lots of ways of doing it. If you wanted more than 9 valves, I'd probably start with the alphabet before moving to two digits. Since DF is not case sensitive, you can only go through it once, but that would get you 36 valves. If you wanted two digits, you just have to change the script a little, making i++ to i+=2, and the 1 inside the mid() to a 2.

Using a string array would work if you didn't want to name the scripts valve1, valve2. Just create the array:

private seqList = {"valve1seq", "anotherValve"}

then change the execute line to:

execute(seqList[strToDouble(mid(order,i,1))])

change the 1 to 2 for 2 digit specifications. Note that you have to use numbers in this case, and 0 is the first one.

Link to comment
Share on other sites

Thanks again! As I am (obviously) a novice at this, could you explain how the string variable "order" (and its length) is related to the seqList array elements? I am confused about this....I tried the sequence with an array set up with the original valve1, valve2, etc., sequence names but the array technique didn't seem to work the same way as your first suggestion. The sequence ran, but didn't return info that the valve sequences were activated.

Link to comment
Share on other sites

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.