Home   Help Search Login Register  

Author Topic: sqs and sqf  (Read 3626 times)

0 Members and 1 Guest are viewing this topic.

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
sqs and sqf
« on: 17 Jun 2009, 11:04:11 »
Hellu,

I haven't done some serious scripting for God knows how long. Let's just say there's been a game in between the current game that I didn't really touch scripting-wise. So as far as I understand, sqs have been declared obsolete and have been replaced by sqf and this has followed onto ArmA2 as well. The old sqs-format is still readable by the engine though, right?

So I'm just wondering if there's any reason for me to learn this new syntax. Is there any real benefit of sqf over sqs? Besides that the code looks nicer compared to the quite horrible sqs-syntax. But I'm a scripter. If I'd care about beauty I'd become an addon maker. ;)

I tried to do a search, but seems that the search function is out of order.

Oh, and where the hell is macca? ???

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: sqs and sqf
« Reply #1 on: 17 Jun 2009, 12:13:04 »
Here's a tutorial on it. It may clear some things up for you.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: sqs and sqf
« Reply #2 on: 17 Jun 2009, 14:03:04 »
SQS is still running fine in A2, for backward compatibility, I assume. It has never been officially declared as obsolete, but it is very much so (remember that obsolete means that it has been replaced by something significantly better that means there is no reason to use it any more; obsolete does not mean that it has stopped "working").

The only argument I can still see for using SQS is that for simple, linear scripts, without any goto commands, SQS runs about as well as SQF. But since such trivial scripts can be written in SQF in almost an identical way, this isn't a compelling reason to stay with SQS. If you ever want to write non-trivial scripts, then you are making life immeasurably harder for yourself by sticking to SQS.

BIS themselves generally wrote in SQS for OFP/A1 (In A1 probably because they were recycling old OFP scripts), but they didn't actually do any advanced scripting before the A2 modules, which are almost entirely in SQF and would have been very difficult, or even impossible, to implement in SQS.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re: sqs and sqf
« Reply #3 on: 21 Jun 2009, 17:54:43 »
Cheers for the replies guys! Now, I just briefly had a looksee at the tutorial that savedbygrace linked to, and as far as I understand it there isn't that much of a difference. How could some things be so much more easy to script if it's basically just a tiny change of syntax?

Oh well. Just my curiosity running wild here. I'd be better off reading the tutorial before I ask any further questions. :D

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: sqs and sqf
« Reply #4 on: 29 Jun 2009, 02:24:24 »
Interesting tutorial. Though I have a long way to go. Here's the example I'm working with now. Founf it in the ArmA2 campaign. It's a SQF that makes the carrir ship play it's engine sound as long as the player remains within a trigger area.

This is the entire script:

Code: [Select]
while {true} do
 {
playSound "LHD_engine";
sleep 6.8;
};

My question is:
* How do I call/start such a script?
* How can I switch it off? It looks as if all I have to do is change a variable to false. But wich one?!?
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: sqs and sqf
« Reply #5 on: 29 Jun 2009, 05:29:38 »
My question is:
* How do I call/start such a script?

-if arma2 syntax is the same as the original, type: [] execvm "script.sqf"

* How can I switch it off? It looks as if all I have to do is change a variable to false. But wich one?!?

All righty here, lets take a look at the script.
Dunno how much you know, so I'll start from the ground up.


Code: [Select]
while {true} do
 {
playSound "LHD_engine";
sleep 6.8;
};

You're right about the variable being switched to false.
However, as written that's impossible.

Explanation: in a while command the condition in the braces {} must be true to loop.
When is true not true? (huh?) Never, meaning this code will loop forever.
Now if you were to change the script to say something like this:
Code: (script.sqf) [Select]
_engine_switch = true;
while {_engine_switch} do
 {
playSound "LHD_engine";
sleep 6.8;
};
you could control it.

as long as the variable _engine_switch is true it will loop.
when you run the code as I have rewritten it it will switch _engine_switch to true and loop the sound.

and since the variable has an underscore (_) in front of it, I believe that makes it a global variable.
In other words, I believe it can be switched true or false by another script.

However, as rewritten, when _engine_switch becomes false, the loop terminates, and the script needs to be re-executed to run the loop again.

Now, if it is re-written again, that won't be necessary to re-execute the script.

Code: (script.sqf) [Select]
_engine_switch = true;
while {_engine_switch} do
 {
playSound "LHD_engine";
sleep 6.8;
waituntil {_engine_switch};
};

This will stop it mid-loop if _engine_switch ever becomes false.
However, it is still technically in the "while" loop, so you won't need to execute it again.

Now for switching it on and off.
Code: (engineswitcher.sqf) [Select]
if (_engine_switch) then {_engine_switch = false} else {_engine_switch = true};
if (isnil _engine_switch) then {_engine_switch = true};

I know it's a simple and short script.
Execute the script by typing: [] execvm "engineswitcher.sqf";

That's all I can think of, and, I know, the post is long. :P

Anywho, hope that helps. :)

Luke
Pesky Human!!
Wort Wort Wort.

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: sqs and sqf
« Reply #6 on: 29 Jun 2009, 08:38:04 »
Thanks Luke. That helped a lot.  :good:
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: sqs and sqf
« Reply #7 on: 29 Jun 2009, 09:26:51 »
and since the variable has an underscore (_) in front of it, I believe that makes it a global variable.
It's local if it has an underscore at the start.

Offline i0n0s

  • Moderator
  • *****
Re: sqs and sqf
« Reply #8 on: 29 Jun 2009, 11:10:56 »
You can terminate a "while {true} do", if it was spawned.
spawn and execVM return a script handle and you can use terminate to terminate a running script.