Jump to content

Recommended Posts

Will the vector functions be updated to use the new commands for backwards compatible optimization?

Edit: Also the distance2Dsqr function could use the new vector commands too. (Also curious as to why it isn't using getPosASL since it's quicker and the height doesn't matter).

Here's distance2Dsqr using the vector command:

scriptName "Functions\geometry\fn_distance2Dsqr.sqf";
/************************************************************
   Distance 2D Squared
   By Andrew Barron


Parameters: [object or position 1, object or position 2]


Returns the SQUARE of the distance between the two objects or
positions "as the crow flies" (ignoring elevation).
Working in the squared domain is a little faster than using the
fn_distance2D function.


Example: [player, getpos dude] call  BIS_fnc_distance2Dsqr
************************************************************/


private ["_pos1","_pos2"];


_pos1 = _this select 0;
_pos2 = _this select 1;


//if objects, not positions, were passed in, then get their positions
if(typename _pos1 == "OBJECT") then {_pos1 = getposASL _pos1};
if(typename _pos2 == "OBJECT") then {_pos2 = getposASL _pos2};


//return SQUARED distance between _pos1 and _pos2
[_pos1 select 0,_pos1 select 1, 0] vectorDistanceSqr [_pos2 select 0,_pos2 select 1, 0]

edit 2: Why is the forum messing up the PHP formatting again? :p It stopped doing it for a while. Changed to plain code

edit 3: Updated to match new vector command syntax with latest dev branch

Edited by SilentSpike

Share this post


Link to post
Share on other sites
Those are handguns aren't they.

Yes. The Pistols have limited items, like the Yorris sight for the Zubr, and MRD for the 4-five. They do come in handy if you can get a hold of them.

Share this post


Link to post
Share on other sites
Yes. The Pistols have limited items, like the Yorris sight for the Zubr, and MRD for the 4-five. They do come in handy if you can get a hold of them.

Handguns are different from secondary weapons is his point. Secondary weapons are things like launchers (all I can think of off the top of my head)

Share this post


Link to post
Share on other sites

What somebody missed was the command for removing secondary weapon items. There are no secondary weapon items (handguns are not secondary weapons) in the game currently so I said it may be missing because of this. Handgun items are okay and they have all necessary commands.

Share this post


Link to post
Share on other sites
What somebody missed was the command for removing secondary weapon items. There are no secondary weapon items (handguns are not secondary weapons) in the game currently so I said it may be missing because of this. Handgun items are okay and they have all necessary commands.

Damn, I probably shouldn't be posting late at night, you're absolutely right. :o

Share this post


Link to post
Share on other sites
What somebody missed was the command for removing secondary weapon items. There are no secondary weapon items (handguns are not secondary weapons) in the game currently so I said it may be missing because of this. Handgun items are okay and they have all necessary commands.

That's correct, the vanilla game doesn't contain secondary weapon attachments, however there are some addons out there with custom launcher optics, for example.

Share this post


Link to post
Share on other sites

There seems to be an issue with BIS_fnc_exportCfgWeapons (or simply some confusion on my part). When called with parameters ["Weapon"] it returns a list the class names and details in wiki formatting as it should.

However, taking a closer look I spot at least one incorrect class name. "srifle_DMR_01_DMS_snds_F" is not a class name. I have tested this using addWeapon and it produces no result (might also be worth mentioning addWeapon throws no error regardless). The correct classname is "srifle_DMR_01_DMS_pointer_snds_F", which does produce a result with addWeapon. I updated this in the wiki list for cfgWeapons but my change was soon undone and I'm wondering if I'm going crazy or whether something really specific and odd is going on here.

Edit: Some further info also. I tested this function on stable branch as I thought the difference may have been due to the class name being changed in an update, but the function still returns the same class names.

Edited by SilentSpike

Share this post


Link to post
Share on other sites

Can addweapon be used as a test of whether something is a valid classname? Addvehicle cannot be used because vehicle classes which are used only for inheritance purposes cannot be spawned in-game. Can you addweapon "default", for example?

Share this post


Link to post
Share on other sites
Can addweapon be used as a test of whether something is a valid classname? Addvehicle cannot be used because vehicle classes which are used only for inheritance purposes cannot be spawned in-game. Can you addweapon "default", for example?

I'm not sure, I simply used it as that was the reasoning behind reverting my change to the wiki. However, I have also been using this piece of script to get a weapon's supported magazines:

// Select a random weapon and fetch the supported magazines
_primary = (getArray (missionConfigFile >> "MissionArrays" >> "primaryWeapons")) call bis_fnc_selectRandom;
_primaryMagTypes = getArray (configfile >> "CfgWeapons" >> _primary >> "magazines");

It doesn't work when the weapon that gets chosen is the falsely given (false as far as I can tell) class name. There also appears to be no such class name in the cfg viewer.

Edited by SilentSpike
Forum breaking PHP formatting yet again...

Share this post


Link to post
Share on other sites
Can addweapon be used as a test of whether something is a valid classname?

isClass?

Share this post


Link to post
Share on other sites

EDIT: nvm. i see it now.

 isClass (configFile >> "cfgWeapons" >> "classname_to_test")

Share this post


Link to post
Share on other sites

Good shout, will give it a go

isClass (configfile >> "CfgWeapons" >> "srifle_DMR_01_DMS_snds_F"); should return true if it's a real weapon class name.

Share this post


Link to post
Share on other sites

if (isClass (configFile >> "CfgMagazines" >> _class) || isClass (configFile >> "CfgWeapons" >> _class) || isClass (configFile >> "CfgVehicles" >> _class) ||isClass (configFile >> "CfgGlasses" >> _class)) exitWith {true};

?

Where _class is your string.

Share this post


Link to post
Share on other sites

No need since the function exports classnames from cfgWeapons only.

It's not a classname according to the command. So it seems something weird is going on with that function.

---------- Post added at 23:22 ---------- Previous post was at 21:41 ----------

It seems that the classname exists on the latest dev branch, but not on the stable build (which I'm running). So I can conclude that the function is actually a clairvoyant and can predict the future.

Share this post


Link to post
Share on other sites

openYoutubeVideo "watch?v=pj66F1tIrGs";

New script command, opens an in-game steam browser window. URL "http://www.youtube.com" appended with the given string. Youtube gives an error even when it tries to load a URL I know works. Not sure why that is.

I was hoping this command was going to do something neat like show a video inside a hint box.

Share this post


Link to post
Share on other sites

Line 53 of BIS_fnc_moduleCuratorAddEditingAreaPlayers could use getPosASL instead of regular old position (since z-axis doesn't matter). Just minor optimization, but since it's looping then every little bit helps.

Share this post


Link to post
Share on other sites

Is it me or do boolean expressions no longer short circuit?

isFalse = {
systemChat "isfalse";
false;
};

isTrue = {
systemChat "istrue";
true;
};

shortTest = {
if(call isFalse && call isTrue) then {
	systemChat "shouldn't print this";
};
};

call shortTest; //prints isfalse and istrue to system chat

Share this post


Link to post
Share on other sites

You shouldn't have ; after false and true to return those bools.

Share this post


Link to post
Share on other sites

The semicolon is fine. Xendance needs to wrap the second boolean statement in the if with { } to make it evaluate lazily (I think it would have been better to break backwards compatibility in favor of having a more common boolean execution system where lazy was the default evaluation).

Share this post


Link to post
Share on other sites

Well isn't that retarded. I did try it with extra parentheses and it didn't work. Didn't think you'd need to wrap then inside another code block :|

I wouldn't call it lazy evaluation though. Short circuiting boolean operands aren't any different from having multiple return statements in a function in different branches.

Edited by Xendance

Share this post


Link to post
Share on other sites

It is lazy evaluation because the default if execution is eager, it will evaluate all expressions, even if they are not needed, which makes things like: isNil "someVar" && someVar != "boop" fail with a generic error.

Share this post


Link to post
Share on other sites
It is lazy evaluation because the default if execution is eager, it will evaluate all expressions, even if they are not needed, which makes things like: isNil "someVar" && someVar != "boop" fail with a generic error.

Expressions are usually evaluated from left to right, not the whole line in eager languages. When you say lazy evaluation I think of Haskell and other that kinds of languages where the compiler can reorder expressions and statements because they're lazily evaluated. That is not the case in SQF, it doesn't reorder anything. The && is just prefix notation for a function that does:

&& = {
 _a = _this select 0; //assume prefix notation
 _b = _this select 1;

 if( not _a ) exitWith { false };
 if( not _b) exitWith { false };
 true;
};

There's no lazy evaluation involved here, the && operation (should) just "short circuit" ( http://en.wikipedia.org/wiki/Short-circuit_evaluation ), as in return immediately when _a evaluates to false.

Share this post


Link to post
Share on other sites

...

if(call isFalse && {(call isTrue)}) then {...

Share this post


Link to post
Share on other sites
Expressions are usually evaluated from left to right, not the whole line in eager languages. When you say lazy evaluation I think of Haskell and other that kinds of languages where the compiler can reorder expressions and statements because they're lazily evaluated. That is not the case in SQF, it doesn't reorder anything. The && is just prefix notation for a function that does:

&& = {
 _a = _this select 0; //assume prefix notation
 _b = _this select 1;

 if( not _a ) exitWith { false };
 if( not _b) exitWith { false };
 true;
};

There's no lazy evaluation involved here, the && operation (should) just "short circuit" ( http://en.wikipedia.org/wiki/Short-circuit_evaluation ), as in return immediately when _a evaluates to false.

For all intents and purposes evaluation of an if statement in SQF is eager with out wrapping elements of the boolean statement in { } to make them evaluate only as needed. Short circuiting does not occur by default, all parts of an if statement, every single expression inside of it, is executed before the values are used to determine the condition. That is eager execution.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×