PDA

View Full Version : Can I do a for next loop?


rookieAI
31-12-2004, 10:20 PM
Is there any possible way to do a for next type loop? I am trying to
write a simple script for manual gear lowering and raising in Pacific
Fighters. What I want to do is press a button once and then have
a script send the 30+ characters to Pacific Fighters to get the gear down
and up. Can it be done? I can't seem to figure it out. I have a script
working for when I hold down the button to raise and lower the gear
manually, but I want to set it and forget it.

It seems like there is no flow control that allows a loop back up in
a sequence. This does make sense that it is this way but I am hoping
there is a solution.

I know that I could send multiple characters in the CMC file, but that is
not very fun.

Am I outta luck?

Thanks,
Rook

Bob Church
01-01-2005, 02:47 AM
Hi Rook,

>> Am I outta luck? <<

Never. :) You're right, though. A For/Next isn't easily accomplished. You have to keep in mind that the script can't "stop" and do something. It has to come in, see if there's anything to be done, do it if there is, and get out of there. Otherwise you stall the whole thing until it's done processing.

What I would do would be to use a button, say JS1.A1 to set a variable to twice the count you want:

if( js1.a1 ) then
a1 = 120;
endif

Something like that. Then put in a block of code tied to the CLOCKTICK and set so it sent one transition per script pass:

if( [ a1 > 0 ] ) then
if( CLOCKTICK ) then
cms.b1 = NOT cms.b1;
a1 = a1 - 1;
endif
else
cms.b1 = FALSE;
endif

You might need to lock out the JS1.A1 block if the loop was already running, the usual little details that crop up, but basically that should do it. When A1 comes off zero, the second block is going to toggle CMS.B1 each time the clock ticks. Use CMS.B1 to send the character. It will keep toggling until enough clock ticks have brought A1 back to zero, which should give you what you want. When A1 is zero, cms.b1 is forced off and the thing should shut up.

Anyway, I think that's what I'd try first, but there are certainly other methods. Just not a For/Next.

Best regards,

- Bob

The StickWorks
http://www.stickworks.com

rookieAI
01-01-2005, 06:55 AM
Bob,

Thanks. That will work. How did you find the CLOCKTICK command/variable?

Rook

Bob Church
01-01-2005, 11:17 AM
Hi Rook,

>> How did you find the CLOCKTICK command/variable? <<

It's in the Users Guide. Find the "CMS Programming Guide" link under "Control Manager Scripting", that will get you to the Table of Contents for the CMS stuff. Then look under "CMS Script Elements" for "Predefined Variables and Constants". There are several special variables and constants there that come in handy now and then.

- Bob

The StickWorks
http://www.stickworks.com