Rommel 2 Posted January 16, 2008 Just quoting and learning off the BIS wiki about functions and the .SQF format as I've been dumbfounded as to its real advantages over .SQS scripts. I have found the answers for its use in SP, but cannot find why many mission makers choose it over .SQS on dedicated servers, is it because rather then lagging the server, it just halts it temporarily while it completes the script? Either way, <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">comment "Return maximum of first and second argument"; private ["_a","_b"]; _a = _this select 0; _b = _this select 1; if (_a>_b) then {_a} else {_b} Say _a was larger then _b, how would this return these values to the script it was running from, and how would I use them? Also, <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">comment "Switch all infantry units to safe mode"; { if (vehicle _x == _x) then { _x setBehaviour "safe" } else { _x setBehavior "safe" } } forEach _this Just comfirming that if vehicle _x did not equal _x then _x would setbehavior to safe if not ('if' statement was wrong) then it would setbehavior "safe" also? http://community.bistudio.com/wiki/Function#Example_3:_Inline_Function call FNC_helloall by itself in say a radio command would return scalarbool array etc? Some of these questions are dumb, even to me, but I just want to see if my thinking is right. Share this post Link to post Share on other sites
kronzky 5 Posted January 16, 2008 Just quoting and learning off the BIS wiki about functions and the .SQF format as I've been dumbfounded as to its real advantages over .SQS scripts. I have found the answers for its use in SP, but cannot find why many mission makers choose it over .SQS on dedicated servers, is it because rather then lagging the server, it just halts it temporarily while it completes the script? Either way, <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">comment "Return maximum of first and second argument"; private ["_a","_b"]; _a = _this select 0; _b = _this select 1; if (_a>_b) then {_a} else {_b} Say _a was larger then _b, how would this return these values to the script it was running from, and how would I use them? Actually, the answer to that is right behind the example in the Biki: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">fMax = compile preprocessFile "max.sqf"; maxValue = [3,5] call fMax; // maxValue is now 5 The "maxValue = [3,5] call fMax;" is where the assignment of the return value happens. You can then use the variable maxValue to do with it whatever you want... Here's the whole thing demonstrated in one file, this time as an inline function. Save it as "inlinedemo.sqf", then call it with "nul=[] execVM inlinedemo.sqf", and you'll see... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">whatsbigger = { private ["_a","_b","_return"]; _a = _this select 0; _b = _this select 1; if (_a>_b) then {_return=_a} else {_return=_b}; _return; }; _x=1; _y=2; _big=[_x,_y] call whatsbigger; player sidechat format["%1,%2: %3",_x,_y,_big]; _x=22; _y=11; _big=[_x,_y] call whatsbigger; player sidechat format["%1,%2: %3",_x,_y,_big]; Also,<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">comment "Switch all infantry units to safe mode"; { if (vehicle _x == _x) then { _x setBehaviour "safe" } else { _x setBehavior "safe" } } forEach _this Just comfirming that if vehicle _x did not equal _x then _x would setbehavior to safe if not ('if' statement was wrong) then it would setbehavior "safe" also? http://community.bistudio.com/wiki/Function#Example_3:_Inline_Function call FNC_helloall by itself in say a radio command would return scalarbool array etc? That example doesn't make much sense, since it will always set the behavior to "safe", no matter whether the unit is in a vehicle or not... Also, in order for this to work, "_this" has to be an array that contains a number of units. (Are you sure this isn't supposed to be "thislist", which is the array a trigger generates?) Share this post Link to post Share on other sites
benreeper 0 Posted January 17, 2008 In answer to your first question, SQS is an outdated, slow, line interpreted programming language that looks like nothing else in the real world. SQF surpasses it in every way and is MUCH easier to use. --Ben Share this post Link to post Share on other sites
Rommel 2 Posted January 17, 2008 Thanks Kronzky, first question really helped, I figured out the second lot aswell. It seems a lot easier for structuring, but damn the bastards who don't tab/space their coding (going off examples in coding in missions)... its just a single line for about 500 screens worth :P. I tabbed it all and it is much easier to understand, but am still trying to find its best use in regular coding which I've gotten myself used too, but you learn something every day aye? Share this post Link to post Share on other sites
benreeper 0 Posted January 17, 2008 You are correct and if the tabbing isn't there, it's difficult to read. Like you, when I look at someone else's code ,that isn't tabbed, I tab it first. Also, sometimes the tabs are there but they don't transfer. The editor I use converts all tabs to spaces automatically so it looks clean everywhere. One thing you will notice that SQS is much faster and less of a burden on the system. Also, SQS will most likely completely disappear in the future. The only reason why it's in Arma is because of it's "OFP Elite" legacy. --Ben Share this post Link to post Share on other sites
Rommel 2 Posted January 17, 2008 One thing you will notice that SQS is much faster and less of a burden on the system. Also, SQS will most likely completely disappear in the future. The only reason why it's in Arma is because of it's "OFP Elite" legacy.--Ben One thing you will notice that SQF is much faster and less of a burden on the system. Share this post Link to post Share on other sites