Home   Help Search Login Register  

Author Topic: Capabilites of Scripting in OFP  (Read 1756 times)

0 Members and 2 Guests are viewing this topic.

TheAbomb12

  • Guest
Capabilites of Scripting in OFP
« on: 30 Mar 2004, 21:30:33 »
Hello,

I have Ofp original and I have recentlly started looking at the available commands in the scripting launugage. Im used to programming in C++ so Im trying to find any simularities in structure of the laungiages.

I was wondering, are there any loop commands (ie  while loops, do while loops, for loops)

also, are there any other commands that are considered "core " commands (such as loops, creating functions, initilazing arrays and variables etcetc).

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Capabilites of Scripting in OFP
« Reply #1 on: 30 Mar 2004, 21:40:45 »
The structure of the scripting language is apparently more like BASIC (remember that?) than C++ though I don't know the latter personally.    There are various forms of loops .... I strongly recommend that you just read the command reference - there are some very helpful sections in addition to the alphabetical listing of commands.     The unofficial version of the comref is also excellent for understanding what's going on, and there is an online official comref in the Editors Depot which has helpful Comments added to many commands.

You say you have "original":   more than anything I recommend you upgrade as far as you can:   version 1 patches to 1.46 from the official site www.flashpoint1985.com.    However you should get Resistance Game of the Year edition - which is still obtainable and usually comes in a $10/$15 new and less secondhand - which patches up to 1.96.     It adds a lot of commands (as well as all the addons, missions, campaigns etc) and if you stick with an early version you'll get very frustrated.    
Plenty of reviewed ArmA missions for you to play

TheAbomb12

  • Guest
Re:Capabilites of Scripting in OFP
« Reply #2 on: 30 Mar 2004, 22:21:17 »
Quote
The structure of the scripting language is apparently more like BASIC


I am somewhat familiar with the structure of Visual Basic.

Quote
However you should get Resistance Game of the Year edition - which is still obtainable and usually comes in a $10/$15 new and less secondhand -
which patches up to 1.96.

This has been recommened to me already, but thanks anyways  :).

anyways ive looked throught the command reference, and frankly its rather sparce in any discription of "core" commands and syntax.

Is there anything else that gives a detailed disciption of Core commands (such as loops, function declaration, if statements,), vairable scope, data types and initialization , and syntax(arithmitec, boolean, and relational operators)? Basiclly, the most common commands and thier syntax.
« Last Edit: 30 Mar 2004, 22:27:23 by TheAbomb12 »

TheAbomb12

  • Guest
Re:Capabilites of Scripting in OFP
« Reply #3 on: 30 Mar 2004, 22:47:22 »
I looked throught the command reference and found some information on operators (+, - , = % , /,  etc). I notice that the boolean and arithetic operators are exactllly like C++.

However,  I would still like more information on if statements and loop statments and other common core commands if possible .

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Capabilites of Scripting in OFP
« Reply #4 on: 30 Mar 2004, 23:24:08 »
But .....but .......but..............it is all in the Command Reference.

? = If

i.e.   ? _z > 10 dosomething

Simple loop structure:

_z = 0

#loop
? _z > 10 : goto "somewhere"

BODY OF LOOP COMMANDS HERE

_z = _z +1
goto "loop"

#somewhere
-
-
-
exit


Hope this helps, but you can read most of this stuff in the command reference.



Planck
I know a little about a lot, and a lot about a little.

TheAbomb12

  • Guest
Re:Capabilites of Scripting in OFP
« Reply #5 on: 30 Mar 2004, 23:47:07 »
Quote
#loop
? _z > 10 : goto "somewhere"

BODY OF LOOP COMMANDS HERE

_z = _z +1
goto "loop"

 :o... goto's? gotos for loops?, there has to be something better than a goto loop

I guess if thats the only type of loop available; otherwise Im going to stay very clear away from all goto commands.

usally most languages have some form of while loops, for example:

Code: [Select]
while (value < = 10){
    dosomestuff();
    domorestuff();
   
}

or for loops

Code: [Select]
for (int i = 0; i < SIZE; ++i){
   dosomestuf();
   domorestuff();
}

both of these types of loops are one way or another in almost every lanuguage.

If you know of any equivlent please tell me, would be neater then a goto loop  ;)

Quote
But .....but .......but..............it is all in the Command Reference

Sorry if this is a bit ignorant, but where?

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Capabilites of Scripting in OFP
« Reply #6 on: 30 Mar 2004, 23:56:17 »
There is a While command:z

  while "z<15" do {z=z+1}

I was only giving a small example of a common loop structure used.

You can get the latest command reference from here:

http://www.flashpoint1985.com/breathe/index.html

Look for Config 1.91


Planck
I know a little about a lot, and a lot about a little.

TheAbomb12

  • Guest
Re:Capabilites of Scripting in OFP
« Reply #7 on: 31 Mar 2004, 00:17:33 »
ok I think I have it now...

I was looking through and found what you said (gee im stupid  ::)). I noticed the way functions are used. I take it functions don't reconize black space or line returns so they require a ; after each line (much like C++); however, scripts need no ;, but it compiles on a line by line basis (am I correct).

Can I use functions inside scripts?

Can I exe scripts inside functions?

Question though; is "if" == "?" in conditional statments ?. I see you use "?", whats the difference?

[edit]
Oh! I think I get it even more now.

? is used in scripts and if is used in functions. Right?

In that case, am I capable of running while loops in a script or does it require a function (or those hideos goto commands  ;))?
[edit]

« Last Edit: 31 Mar 2004, 00:26:15 by TheAbomb12 »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Capabilites of Scripting in OFP
« Reply #8 on: 31 Mar 2004, 00:32:13 »
OK

? is a shorthand way of saying IF
! is a shorthand way of saying NOT
&& is a shorthand way of saying AND
|| is a shorthand way of saying OR
@ is a shorthand way of saying "Wait till condition is true"

i.e.    @(z=10)

Both methods can be used.

Just read through the reference, you will pick up a lot of usefull information and tips.

Not too sure but I think you can call a function from a script, but the script waits for it to return...........as I said I'm not too sure about that.

I don't know at all if you can call a script from a function.

Maybe someone else can clarify these points, but the command reference mentions functions in Scripting Topics Section.


Planck
« Last Edit: 31 Mar 2004, 01:01:27 by Planck »
I know a little about a lot, and a lot about a little.

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Capabilites of Scripting in OFP
« Reply #9 on: 31 Mar 2004, 00:41:22 »
I think there's a tutorial on functions.

There are also hundreds of scripts in the Ed Depot which you can take to bits.

You're right that scripts don't need ; at the end of a line, they just figure it out for themselves.  Blank lines are fine.
Plenty of reviewed ArmA missions for you to play

TheAbomb12

  • Guest
Re:Capabilites of Scripting in OFP
« Reply #10 on: 31 Mar 2004, 00:48:26 »
Quote
? is a shorthand way of saying IF
! is a shorthand way of saying NOT
&& is a shorthand way of saying AND
| is a shorthand way of saying OR

Ok, just asked about if, knew about all the other ones (infact, I think OR is "||") because C++ is exactlly the same with the exception of if

Quote
the command reference mentions functions in Scripting Topics Section.

Yes it does, thats where I found the info; however, the info is somewhat brief

anyways, Ill check out the tut on functions and I am already checking out various scripts; I understand most of the scripts and I will be trying out my own things tonight maybe  :D
« Last Edit: 31 Mar 2004, 00:49:41 by TheAbomb12 »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Capabilites of Scripting in OFP
« Reply #11 on: 31 Mar 2004, 01:00:26 »
Yes a good example of a typo I missed, it should be || and not |.

Corrected now.

Planck
« Last Edit: 31 Mar 2004, 01:01:05 by Planck »
I know a little about a lot, and a lot about a little.

Offline Razorwings18

  • Contributing Member
  • **
  • I'm NOT a llama. I checked.
Re:Capabilites of Scripting in OFP
« Reply #12 on: 31 Mar 2004, 04:54:28 »
A couple more pointers and side info, Abomb. First of all, the "?" command doesn't allow for an "else" statement. It is also kept mainly for backward compatibility with pre-Resistance scripts.

Other than that, the problem with "if" and "while" statements is that, within SCRIPTS, you can't use multiline statements, i.e.:

if (a > b) then
{
         thisone;
         thatone;
}
else
{
         otherone;
};

Instead, you'd have to do the whole thing in a single line:

if (a > b) then {thisone; thatone;} else {otherone;};

Which is kind of a pain when it comes to ease of debugging -lack of indenting- especially when doing long and complex code. Therefore, I sometimes still find myself using the "?" statement. Same applies to "while".

Now, in FUNCTIONS this restriction does not apply.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Capabilites of Scripting in OFP
« Reply #13 on: 31 Mar 2004, 05:43:51 »
Quick question: do you have resistance?

If not, then I'm afraid you can't use 'if', 'else', or 'while'. Nor can you define and use functions. Basically, pre-resistance, you are stuck with using spagetti code; using "goto" to jump all over the place. Poor programming practice yes, but it usually works fine considering most scripts are much smaller than, say, a real program.

With resistance, those nifty little commands were added in that make scripting more like a 'real' programming language; the 'if','else','while' and functions.

Personally, I still use the old ? in scripts to do my if statements, simply because its faster to type (and I got used to it before upgrading to resistance). I usually only use "if" if I need an "else" in there too. An important note is that you can also provide multiple commands in a single ? statement, just like an if statement-- they just have to be separated by a semicolon.

Keep in mind you can use ALL of the functions/syntax found in the comm ref in scripts. You can use '?' or 'if', you can use 'while' loops, you can make function calls to your own functions using the 'call' command, you can execute scripts using the "exec" command, and you can use @condition and ~delay to pause the script for a time.

In your own functions (.sqf files), you can also use all of the same commands, with a couple exceptions: you cannot delay the function (using @ or ~ ), and you can't use the '?'. Come to think of it, I don't think you can use the "goto" function either. You can still call functions using the "call" command, and still execute scripts using the "exec" command though.


Personally, I think you should just 'give in' and use the "goto" command. It seems like it would be more work to try to avoid ever using that command than it is worth. You will most likely end up with a ton of different .sqs and .sqf files, when you could fit them all in one or two .sqs files using the "goto" command. In the end that would just make things more complex and hard to understand, instead of making them simpler; which I assume is your reason for wanting to avoid the "goto" command in the first place.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Razorwings18

  • Contributing Member
  • **
  • I'm NOT a llama. I checked.
Re:Capabilites of Scripting in OFP
« Reply #14 on: 31 Mar 2004, 05:54:49 »
Quote
I think you should just 'give in' and use the "goto" command

Indeed  :D
Here're the "templates" I use for scripting. I just paste this whenever I have to use a FOR or WHILE, and use the REPLACE feature of the text editor on the things between "<>":

WHILE
---------
#STARTWHILE<NAME>
   ?(<ENDCONDITION>): goto "ENDWHILE<NAME>";
   <COMMANDS>

   goto "STARTWHILE<NAME>";
#ENDWHILE<NAME>


FOR
-----
_i = <COUNTINI>;
#STARTFOR<NAME>
   ?(_i == <COUNTEND>): goto "ENDFOR<NAME>";
   <COMMANDS>

   _i = _i + 1;
   goto "STARTFOR<NAME>";
#ENDFOR<NAME>


Hope you find these useful.