(08-16-2014, 08:34 PM)Phantom link Wrote: [ -> ]I guess I can use a python example of print on why.
Back in 2.0 print "hi" works
In 3.0 print "hi" fails so you have to do print("hi")
Just how the compiler interprets it.
It's not the same, actually. Python 2 vs 3 has made a few deliberate changes, which included unification of function calls.
In the case of "crew count H1 == 1", it's simply the syntax that is wrong.
"crew" expects a single argument, an Object type. H1 is such an object type. Crew returns an array with the crew of the vehicle.
"count" is a function that (among other things) counts the entries in an array. That is, it requires an array as an argument and returns an integer.
crew count H1 doesn't make sense. count cannot count h1, since it is a vehicle. It needs an array, so you must give it an array.
so, at best we're at "count crew H1". Now, Varanon put brackets around crew h1. This isn't because count is a function, there is no such concept in SQF. What it does, however, is establish precedence. count crew H1 can be interpreted left-to-right or right to left, or outer-to-inner vs. inner-to-outer. Without brackets, it can be interpreted as "(count crew) H1" or "count (crew H1)". If the rules aren't clear, then it is better to explicitly give a precedence by using brackets.
BTW, an interesting tidbit about SQF. While the language looks weird to anyone that knows a normal programming language, there are a few governing rules that make it extremely simple. Everything in SQF is an operator and either accepts zero, one or two argument.
Zero argument operators are for example "west", "player", etc. They don't have any argument and just deliver a result. Single argument operators expect their argument on the RIGHT side of the operator, and (usually) yield a result (which can be nothing). Examples for this are "count", "group", "units", etc.
Finally, binary operators are those that expect arguments on both sides. Examples for this are "createVehicle", "addWaypoint", "setMarkerPos" etc. Some operators like count exist in more than one version. Count can also be prefixed by code, which should return a boolean value. For example
{alive _x} count allUnits
counts all units from "allUnits" that are alive.
All the control structures like if statements, while loops etc. are operators too. Interestingly, the main oeprator for a conditional is "then". 'then' is a binary operator accepting an "if-type" on one side and a piece of code on the other side. "if-types" are only returned by the (unary) if operator. So:
if (condition) then {code};
"then" takes the if-type returned by if and executes code only if it is true.
if (condition) then {code} else {code2};
else is kind of like a switch statement. else is a binary operator and returns either its left ("code") or right ("code2") argument based on the if-type.
Same with while. The "real" loop operator is "do". It exists in two versions, with either a switch or a while type.
You probably get the idea.
Knowing these rules actually makes the language quite clear.
(if you read this up to here, congrats
)