Home   Help Search Login Register  

Author Topic: To sqs or sqf, that is the question...  (Read 14645 times)

0 Members and 1 Guest are viewing this topic.

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: To sqs or sqf, that is the question...
« Reply #15 on: 21 Jan 2010, 18:19:27 »
...never tried .sqf until everyone started saying .sqs was obsolete for Arma II...

My output has admittedly been very low since the release of ArmA2. But I still write scripts every now and then, and I still use sqs from time to time. That way I can use script snippets from the early OFP-days, with a simple cut and paste.
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Gielovic

  • Contributing Member
  • **
Re: To sqs or sqf, that is the question...
« Reply #16 on: 23 Jan 2010, 15:55:09 »
marginally faster processing.

If I remember correct, SQF was first only used for creating new functions and wasn't at all useful as a replacement for SQS because the game was suspended  until the function you created finished.

I think this is still the case if you compile the sqf-script as a function and then call it. With execVM the script is interleaved with the main program thread and it runs like sqs does (next to the 'game' itself).

Correct me if I'm wrong.

Of course SQF is much more convenient as it looks more like modern day programming languages, with control flow structures like while and for loops.
Also consider Dijkstra's statement: 'goto's are harmful!'  -exactly the statements which are used for looping in SQS- and the conclusion is inevitable:  use SQF!

Edsger Dijkstra (dutch)
Edsger Dijkstra (english)

Offline Dajan

  • Members
  • *
Re: To sqs or sqf, that is the question...
« Reply #17 on: 05 Feb 2010, 22:00:49 »
Sorry to reopen this but I tried experimenting earlier with some of what has been said here, specifically advise from Gielovic:
Quote
You could also pass a list of values to the script, a so called 'array'. An array is denoted by the square brackets with comma seperated values in between.
if your first line of code would be

Code: [Select]
_who = _this select 0 you should have passed  an array to the script ([nameofsomeunit]), and the first element (with index 0), would be assigned to the variable _who.
More on the select statement can be found in the Biki

This way you can make scripts to which you can pass multiple units, or other elements like static objects, tanks, groups of units, etc...
I took this to mean that i could, say rearm a group of units via a simple .sqf by using a trigger with the following it its on activation field:
Code: [Select]
nul0 = [tom,dick,harry] execVM "myscripts\newloadout.sqfhowever even with the suggested change to the first line of code this only rearm the first unit (i.e. tom)
Did I misunderstand something in Gielovic's advice or am I missing a vital step somewhere?
« Last Edit: 05 Feb 2010, 22:11:28 by Dajan »

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: To sqs or sqf, that is the question...
« Reply #18 on: 05 Feb 2010, 22:20:41 »

maybe you need in script another 2 x who

you send to script [tom,dick,harry]

script
reads

tom =  _this select 0
dick =    _this select 1
harry  = _this select 2

so
_who = _this select 0 // this means tom  and so later in script if you only say

_who addmagazine _x   // then only tom will add the magazine


you will need _who1 =_this select 1  and _who2 =_this select 2   

and then _who2 addmagazine _x     and _who3 addmagazine _x    etc.

 i must say here tho its already becoming too much  and you need to read about array and or Foreach.

i am busy at moment hope this helps a little and some other can contribute to finish.


I love ofp

Offline Dajan

  • Members
  • *
Re: To sqs or sqf, that is the question...
« Reply #19 on: 05 Feb 2010, 22:26:29 »
Ah thanks DeanosBeano, think I did the classic jumping feet first without checking the water! I'll get back on the BIKI and see if I can work it out  :-[

Offline Gielovic

  • Contributing Member
  • **
Re: To sqs or sqf, that is the question...
« Reply #20 on: 05 Feb 2010, 22:44:56 »
passing an array of values gives you the possibility to use more than one input parameter.
I think its good practice to always use an array.
What your want to do actually is rewriting the script so that not a unitname has to be passed but an array (list) of units is passed to which the script is applied iteratively.

This can be done by creating a newscript say applytoall

which does the following
Code: [Select]
inputlist = _this select 0 //The first element passed has to be an array
// So call this function by [[element1,element2,..,elementn]] execVM ...

//This executes your original script for each individual unit.
{nul = [_x] execVM yoursoriginalscript.sqf } forEach inputlist


These scripts can be merged very easily but it wouldn't be a bad idea to seperate them.
Perhaps you can compile your original script and make it an actual function that can be called using the call  operator.

Offline Dajan

  • Members
  • *
Re: To sqs or sqf, that is the question...
« Reply #21 on: 05 Feb 2010, 23:04:35 »
Head... starting.. to... spin...
Thanks gielovic, will look into it!
Does anyone know of any missions out there where someone used .sqf and arrays in the fashion I'm talking about - I might be able to get my head round this faster if I can examine something that works and do some re-egineering of it?

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: To sqs or sqf, that is the question...
« Reply #22 on: 06 Feb 2010, 03:04:08 »
Hi Dajan,

To sqs or sqf? I find there is a lot of "snobbyism" here... my personal opinion.

Arma2 still supports .sqs which tells you it is not obsolete yet.

People in general advocate .sqf even when it isn't needed, that's my view. I guess some of us are just interested in making our missions/scripts to work, some people want a very clean code as a first priority.

When I design missions, I just want stuff to work the way I intended, and often .sqs is the simplest (old fashioned way) to do that. .sqs is my spontaneous way of scripting (since OFP days) and only if it's really necessary I will convert it into .sqf.

For example: If the script has to be run very often during game, I try to use .sqf because it supposedly demands less resources from your pc, but a script that only runs once (like camera/intro) runs just as well (or better) in .sqs.

Anyway, that's my view (but I'm still an old time OFP scripter)

Laggy
« Last Edit: 06 Feb 2010, 03:25:43 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline zonker3210

  • Members
  • *
Re: To sqs or sqf, that is the question...
« Reply #23 on: 06 Feb 2010, 03:12:37 »
I'm not sure if this is the sort of example for which you're seeking but...

In some missions I've made, I like to add IEDs via Jeevz' IED script. (Note that it's in SQS format! ;) ) Anyhow, I didn't like having specific IED locations...I wanted them to be random so that players couldn't be sure whether or not it was safe to walk near that car...that garbage can...that pile of trash near the road. So I wrote a script to randomize the locations of the IEDs. To use it, you simply place a series of empty objects on the map, name them (i.e., "ied1", "ied2", "ied3", etc.) and then add the following line to the mission's INIT.SQF file...

Code: [Select]
[
  [
    [ied1, "Large", 15],
    [ied2, "Huge", 30],
    [ied3, "Large", 15]
  ]
] execVM "IED_Randomizer.sqf";

Essentially what this does is it identifies possible IED locations in the map (ied1 thru ied3) and specifies both the size of each IED (Small, Medium, Large, or Huge) and the distance at which it will be triggered. For example, if ied1 is made active, then it will be a Large IED triggered when someone comes within 15 meters of its location. Whether or not a particular location is made into an actual IED is based on the script equivalent of flipping a coin ("round(random 1)").

Well, I'm sure you get the idea so here's the randomization script itself (see below). Note that the input parameters are in nested array form and I can add more possible IED's simply by adding more entries to the parameter array.

Hope this helps,
 -z

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
IED_Randomizer.sqf
Code: [Select]
// ----------------------------------------------------
//
//  IED_Randomizer.sqf by zonker3210
//  created: 10-Jun-2009
//
//  Intended for use with the IED.SQS script made
//    by Jeevz. The IED.SQS script may be found here:
//
//    http://www.armaholic.com/page.php?id=504
//
//  The script below allows for somewhat random IEDs
//    from a pool of potential IEDs. Should be
//    referenced in your INIT.SQF file like so...
//
//    [
//      [
//        [ied1, "Large", 15],
//        [ied2, "Huge", 30],
//        [ied3, "Large", 15],
//        [ied4, "Small", 5],
//        [ied5, "Medium", 15]
//      ]
//    ] execVM "IED_Randomizer.sqf";
//
// ----------------------------------------------------

if !(isServer) exitWith{};

private ["_trigger", "_activateIED", "_iedArray"];
_activateIED = 0;
_iedArray = _this select 0;

if (isNil "Ied_Setup_Completed") then
{
  //loop thru each item in the array of potential IEDs...
  {
    // get a pseudo-random number; 0=false, 1=true
    _activateIED = round(random 1);
   
    if (_activateIED > 0) then
    {
      // ------- debugging statement -------
      //hint format["%1 is active", _x];
      // -----------------------------------
     
      // Create a trigger at the location of the potential IED. When activated,
      //  the trigger will call the IED.SQS script using the specified IED object
      //  and blast size.
      _trigger = createTrigger["EmptyDetector", (getPos (_x select 0))];
      _trigger setTriggerArea[(_x select 2),(_x select 2),0,false];
      _trigger setTriggerActivation["WEST","PRESENT",false];
      _trigger setTriggerStatements["(thisList select 0) isKindOf 'Man'", format["[%1, ""%2""] exec ""ied.sqs""", (_x select 0), (_x select 1)], ""];
    };

    sleep .5;
  } foreach _iedArray;
 
  // set the nil variable with a default value for server and both JIP & 'join at mission start'
  Ied_Setup_Completed = true;
  publicVariable "Ied_Setup_Completed";
};
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

Offline Dajan

  • Members
  • *
Re: To sqs or sqf, that is the question...
« Reply #24 on: 06 Feb 2010, 20:18:13 »
Hmm.. thanks zonker. I'll have a toy about. I don't suppose you've published any of these missions have you? A little hands-on can solve some of my more pointless questions

Offline zonker3210

  • Members
  • *
Re: To sqs or sqf, that is the question...
« Reply #25 on: 07 Feb 2010, 01:30:22 »
The only one I released to the public was Afghan Village Raid but that was an Arma mission and it requires four addons. If you can wait a day, I'll put something together for Arma2....just a quick example using Jeevz' IED script and the randomizer script mentioned above.

Another (and possibly more helpful) example of passing arrays as parameters in script calls is shk's Taskmaster script. Depending on how comfortable you are with scripting, it might be a bit tough to follow all the way through, though.

I'll try to get a basic example together by tomorrow.

UPDATE: sample attached
« Last Edit: 07 Feb 2010, 08:22:32 by zonker3210 »

Offline Dajan

  • Members
  • *
Re: To sqs or sqf, that is the question...
« Reply #26 on: 07 Feb 2010, 13:56:28 »
@zonker
You just became my own personal god. Thanks for taking the time to do this, I'll give it a spin asap! :good:

Offline Gielovic

  • Contributing Member
  • **
Re: To sqs or sqf, that is the question...
« Reply #27 on: 07 Feb 2010, 23:34:47 »
some on-topic then..

I guess some of us are just interested in making our missions/scripts to work, some people want a very clean code as a first priority.

Sure it needs to work, and that is why you shouldn't use SQS :P. It is not a coincidence that for example BASIC evolved into a form which does not have goto statements.

Programs (and ofp scripts) are way easier to understand if they use standard control flow structures like while loops and if statements. It is much easier to make a mistake when using goto's.

I do agree with you that SQS suffices if you are making cutscenes and you just needs to execute a list of camera actions. But for the actual scripting I would prefer using SQF,