Jump to content
Sign in to follow this  
ralphwiggum

Loops, BIS?

Recommended Posts

Maybe it's me getting drunk again, but I wish BIS would have some sort of loop command for scripts.

Like for-loops or while-loops from C++

would make my editing much easier

Share this post


Link to post
Share on other sites

Sure,, a loop is created by adding a 'loop startpoint', and a command to jump to that point:

#NextRound

<code>

goto "NextRound"

This will make the <code> 'looped'. Pretty basic.

In combination with the command similar to if;then;else statement in normal programing, you can do some funky stuff.

normal programing

If <logical expression>

then "action A"

else "no Action"

in OFP

?( <logical expression> ) : "action A"

"no action"

the colon ( : ) means then,, and the line on the second row is the else part.

;--- Example: loop

#StartOfLoop

~0.1

?(aP distance aPlead > 100) : goto "WarnaP"

goto "StartOfLoop"

#WarnaP

hint "Get back in formation"

~20

goto "StartOfLoop"

What this will do? It will check if unit aP's distance to aPLead is greater than 100m. If so, a hint will appear, telling aP to get back into formation, and then waiting for 20 seconds before checking aP's distance to aPLead again.. If not, it will continue to check this every 0.1 seconds.

SO,, yes,, loops are a essential part of scripting smile.gif

Share this post


Link to post
Share on other sites

biggrin.gif Thanx Snake...But I know that much!

I just wished that OFP Scriptiing with for-loop would be easier for some people... like

for (_x=0; _x<=_numOfSoldiers; _x++)

{

//do whatever you want to do

}

would be easier for me......I ran into this loop nagging while I was making a loop that ends if certain conditions are met, but the script doesn't.

Thanx for your feedback! biggrin.gif

Share this post


Link to post
Share on other sites

you can do this kinda stufff :

for (_x=0; _x<=_numOfSoldiers; _x++)

{

//do whatever you want to do

}

but you just have to use diffrent syntax which you can find in the command ref.

RED

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (iMoRtAliS @ Feb. 09 2002,08:07)</td></tr><tr><td id="QUOTE">Actually in C++ "?" is a valid way to say IF and ; Can replace ELSE...<span id='postcolor'>

aye! wow.gif

Share this post


Link to post
Share on other sites

>would be easier for me......I ran into this loop nagging while I was making a loop that ends if certain conditions are met, but the script doesn't.

Loops can finish without exiting the script.

You saw how they made it - and after all, when converted to machine code all of them work in a similar way.

for (_x=0; _x<=_numOfSoldiers; _x++)

{

//do whatever you want to do

}

will be translated to (this is how you'd write it in opfish)

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

;using minus the incrementor makes it a bit simpler.

_x = -1

#loopstart

_x++

? (! _x<=_numOfSoldiers) : goto "loopend"

...

goto "loopstart"

#loopend

<span id='postcolor'>

That is essentially how the c++ for statement is translated into machine code.

>Actually in C++ "?" is a valid way to say IF and ; Can replace ELSE...

What? This can't be ansi c++.

Perhaps ? as if will work, but ; will certainly not replace else. It is always a "command finished" marker.

if (value) foo();

command();

Will always run command(), even with more ; inserted e.g. in front of command. Unless you have a very non-compliant compiler?

<getting tired>

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×