Arma 3
Papa Creech 2017 年 9 月 12 日 下午 8:08
Scripting help
Hey guys I'm currently trying to learn scripting for ama 3, I have found a script and I am going through it to see if I can understand what it is trying to say. I was doing pretty well until I came across this section. I'm not really sure what select means, I've looked at the BIS wiki and read about it but I still can't quite grasp what select any of the selects mean, any help would be appreciated.

else {
_possTar = _unit nearTargets _maxDistance;
if ((count _possTar) > 0) then {
_i = 0;
_hold = 0;
{
_i = _unit aimedAtTarget [_x select 4,"autocannon_35mm"];
if (_i > _hold && (_x select 3) > 0) then {
_target = _x select 4;
_tarPos = _x select 0;
_hold = _i;
};
} forEach _possTar;
};
};
< >
正在显示第 1 - 6 条,共 6 条留言
SeraphinicIna 2017 年 9 月 13 日 上午 12:36 
with "select", it's possible to select a value from an array or a return value of a variable/script command.

e.g
arrayPool = [1, 2, 3, 4, 5]; mySelection = arrayPool select 2;
/in this case, the number 3 will be selected and stored into this variable. Why 3 and not 2? Because the index starts at 0 and not 1. The number "1" in the arrayPool is index 0 - so if you want to select that you will have to write
mySelection = arrayPool select 0;
That was when you select something from an pool, next one is to select items which are returned by an script command:

Let's take the command weapons[community.bistudio.com]. There you can see that the return value an array of worn weapons from the unit is.

selectedWeapon = (weapons player) select 1;
The "weapons" command gets all weapons the player have and with select 1 we select the weapon class name that is returned on the second index (first index 0, then 1) and stores it into the variable. This is, if you don't have a laucher equipped, most likely the pistol.

And that's in general the magic behind the "select". The number behind the select is the index that is chosen from the array/return value.

最后由 SeraphinicIna 编辑于; 2017 年 9 月 13 日 上午 12:39
Papa Creech 2017 年 9 月 13 日 下午 7:02 
Okay, thanks, that makes a little more sense, do you know what the _x select 4, and _x select 3 in the script is calling? If I need to show more of the script I can
MATTXYO 2017 年 9 月 14 日 上午 3:20 
引用自 Justbeast11
Okay, thanks, that makes a little more sense, do you know what the _x select 4, and _x select 3 in the script is calling? If I need to show more of the script I can

Select 3 and select 4 in this instance are explained here: https://community.bistudio.com/wiki/nearTargets

The script is pulling information from the array returned by the nearTargets command, see Nobodys description above regarding arrays :-)

The _x preceding the selects represent information regarding one of the Possible Targets (_possTar) if any, during each iteration of the forEach loop.

_x select 0 = Objects Position

_x select 3 = Subjective Cost

_x select 4 = Object

Hope thats makes sense :-)
最后由 MATTXYO 编辑于; 2017 年 9 月 14 日 下午 4:12
Papa Creech 2017 年 9 月 14 日 上午 6:14 
Ahh, thank you so much! I was looking in the wrong place, I was looking at the aimedAtTarget command for the array, but I see what you're talking about with the nearTargets. Was it just experience that made you look there or was something in the code told you to check nearTargets?
MATTXYO 2017 年 9 月 14 日 下午 5:00 
引用自 Justbeast11
Ahh, thank you so much! I was looking in the wrong place, I was looking at the aimedAtTarget command for the array, but I see what you're talking about with the nearTargets. Was it just experience that made you look there or was something in the code told you to check nearTargets?

I would say a bit of both.

Looking at the code I seen the forEach _possTar, then I looked at what information _possTar holds, that being nested Arrays containing info on Targets within a _maxDistance (which will be defined further up in the script) from the _unit.

One of the best pieces of advice I could give is to always read what the return value of a command is.

Using the Wiki example for the return value nearTargets:

[**[[2555.33,2535.33,1.32708],"SoldierEB",EAST,214222,EAST 1-1-A:1]**,
**[[2550.39,2482.5,1.32696],"SoldierWB",WEST,0,WEST 1-1-A:2]**]

The array in between the first ** (I added the ** to split the nested arrays) will be first selected array on the first run of the forEach loop followed by the next (There maybe alot more depending on targets in distance), each of the nested arrays hold all the info on a particular object which you can pull using the select command.

First run of forEach _possTar

_x select 0 would be [2555.33,2535.33,1.32708] the objects Position. (Position is an array)

_x select 1 would be "SoldierEB" the Objects classname. (Classname is a "string")

etc

Second run of forEach _possTar

_x select 0 would be [2550.39,2482.5,1.32696]

_x select 1 would be "SoldierWB"

etc

By doing this you can use the return values for other commands such as aimedAtTarget.

The aimedAtTarget requires the following:

vehicle aimedAtTarget [target, weapon]

So a vehicle, a target, and a weapon.

The script uses _unit for the vehicle (defined further up the script).

_x select 4 is the Object (target) pulled from a nested array within the _possTar array, remembering that _x represents the first nested array in the first run of the forEach loop then the second nested array in the second run and so on.

And finally a weapon which is the "autocannon_35mm".

And so,

_unit aimedAtTarget [_x select 4,"autocannon_35mm"];

******************************************************************************************
To provide a further example of nested arrays:
nestedArrayPool = [[1, 2, 3, 4, 5], [6,7,8,9,10], [11,12,13,14,15]] mySelection = nestedArrayPool select 1 select 2; mySelection would then have the integer 8 store in it.


Again hopefully that made sense to you and I didnt just waffle on.
最后由 MATTXYO 编辑于; 2017 年 10 月 13 日 下午 6:19
Papa Creech 2017 年 9 月 14 日 下午 5:18 
That did help! Thank you so much! I still have a lot of learning to do, but I think I'll get the grasp of it! Again, I really appreciate the time you have taken to explain this to me
< >
正在显示第 1 - 6 条,共 6 条留言
每页显示数: 1530 50

发帖日期: 2017 年 9 月 12 日 下午 8:08
回复数: 6