Home   Help Search Login Register  

Author Topic: sqf v.s sqs a question from a "less capable" mission maker  (Read 1676 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Hi all... again.

Quick question.

sqf stuff is way above my capability at this point. It just seems like a league superior to my own right now. I feel quite confident with sqs though.
Does sqf behave any differently from sqs in terms of locality or necessity of PublicVariable to make it MP safe?
sqf seems more intergrated with the game engine somehow... or?

What is "this new fuzz about sqf all the time" asks an old OFP mission designer, now hooked on ArmA (not surprisingly maybe).

Cheers.

Laggy
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: sqf v.s sqs a question from a "less capable" mission maker
« Reply #1 on: 22 Mar 2008, 03:22:10 »
locality of variable publication is the same in both sqs and sqf.

sqf is more efficient for scripts where you have tigh loops with quite small delays between iterations. sqf also provides you with a far more potent structured programming.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: sqf v.s sqs a question from a "less capable" mission maker
« Reply #2 on: 22 Mar 2008, 13:23:20 »
SQF is also a lot more efficient when you run the same file more than once, since you can pre-compile code into a function. In SQS you always have to compile the script each time it is run.

Remember that you can still use most, if not all, of the SQF structures in SQS, as long as you keep them on one line, so you needn't make the leap to SQF in one go. You might even realise that you are using some SQF already in your SQS! e.g.
Code: (SQF formatted structures, but kept on a single line so they are usable in an SQS file) [Select]
if (x > 3) then { hint "hello" } else { hint "goodbye"; };

_total = 0;
{ _total = _total + _x } forEach _array;

myfunction = { hint "fish!"; sleep 5; hint "frog!"; };
call myFunction;

Maybe just picking an aspect of SQF at a time to pepper into your SQS might help you make the "leap" more gradually? You also don't need to use all the functionality of SQF at once. You can, for example, get by fine without ever using functions for a long while.

Remember too that SQF's structured approach is very like modern programming languages, so if you ever think you might move into other programming, even if it is just some scripting for another game or some JavaScript in a web-page, then the SQS mindset is a bit of a dead end. The reason that modern programming uses a structured approach (like SQF) is that once you've got over the ideological hurdle of moving to that style, you will write programs much faster, they will be shorter, faster in execution and with less bugs than you would have using unstructured code. Other people will also be able to read the code much faster, so being able to help with problems quicker, due to its inherent structured nature. There are plenty of reasons why mainstream programmers universally made the move from unstructured to structured programming decades ago (admittedly, they have since made the leap to object-oriented programming style, but we don't have an object-oriented script format in ArmA, so I can't advocate that...yet ;P ).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: sqf v.s sqs a question from a "less capable" mission maker
« Reply #3 on: 22 Mar 2008, 16:06:11 »
I had this same "problem" when I got ArmA, to move over from all the stuff I knew about .sqs and OFP scripting. I started by making most of my scripts in .sqs, and then piece by piece converting them to .sqf. After a while, you won't want to use .sqs for anything much anymore - remember even the code written in waypoints, triggers etc. is basically in .sqf format! So it's definitely worth learning.

The commands are, after all, all the same - there are just more squiggles around. For instance, to create a loop in SQS, you'd so something like:

Code: [Select]
_i = 0;
#Loop
_loon setpos getpos _loon2
~0.1
_i = _i + 1
?! _i > 10 : goto "Loop"

To do the same in .sqf, you just gotta use while...do

Code: [Select]
_i = 0;
while {_i < 10} do {_loon setpos getpos _loon2; sleep 0.1;}

Looks a lot cleaner, don't it? :D Anyway - good luck, you'll make the conversion yet.

Wolfrug out.


"When 900 years YOU reach, look as good you will not!"

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: sqf v.s sqs a question from a "less capable" mission maker
« Reply #4 on: 22 Mar 2008, 17:53:07 »
Thanks all of you.

I'm starting to look into it. Found the sqf basic tutorial as well. I guess my problem is that with sqs you could understand easier logically how everything worked, while sqf code is more... eh... coded.

I'll be back.

Laggy


And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: sqf v.s sqs a question from a "less capable" mission maker
« Reply #5 on: 25 Mar 2008, 17:41:21 »
I think you are cheating a bit there, Wolfrug, since by putting so much on one line, it appears that the script is shorter, when really it is pretty much as long as the SQS version. You also forgot to increment _i and the semi-colon after the final }, but I know they are just things you forgot in a rush ;P You have to remember that good, clear formatting and white space are as important to make code readible and simple as is brevity of lines-of-code:
Code: [Select]
_i = 0;
while { _i < 10 } do
{
    _loon setpos getpos _loon2;
    sleep 0.1;
    _i = _i + 1;
};

Also, although this is a literal conversion of the original code to SQF, this same thing can be done with:
Code: [Select]
for "_i" from 1 to 10 do
{
    _loon setpos getpos _loon2;
    sleep 0.1;
};

This method has two advantages:
* The counter, _i, is automatically created for you and only exists within the for loop (as if you'd used the private command). In this example, _i isn't being used inside the loop either, but that is just more of a reason not to have it exist outside the loop itself, where it could interfere with other "versions" of _i.
* It is easier to avoid counting errors, common with loops, since it is even more obvious that you are counting 1 to 10 inclusive (looping 10 times). Whenever you are messing about using <, <=, > or >= for looping, it is not as clear exactly how many times the loop will be being repeated. I know it is "easy" to get it right, but we shouldn't need to make any effort for something so fundamental to scripting, when there are plenty of "complex" things to be causing us headaches already ;P
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: sqf v.s sqs a question from a "less capable" mission maker
« Reply #6 on: 25 Mar 2008, 17:56:53 »
 :D This is why you're never online anymore to answer all my stupid questions via MSN, eh, Spooner? Yes - mistakes made in a hurry, I suck.  :-[ One does learn though, albeit slowly!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"