Jump to content

Recommended Posts

Could someone be so kind as to explain exacly what "_this select 0" and (_this select 0) and select 0 means as well as _x? I've searched it up but seen different explenations all over, such as "It chooses an object from the array that it was exectued from" but after that i see "_this select 0" in the beginning of an init.sqf. _x i have no clue about. Thanks for reading and hopefully i can understand this.I'm just a new guy trying to learn scripting for arma  :)

Share this post


Link to post
Share on other sites

I understand that "_this select 0" and so on chooses an object from an array but what I don't understand is what it has to do with "_target, _caller and _object (I think)" as well as what it means when it's in the beginning of a script line where it looks like it and has no connection to any array. I didn't quite understand what "_x" does as well  :(

Share this post


Link to post
Share on other sites

Here's an array, which is just a list.

 

_stuff = ["chocolate", "beer", "women", "cars", "gaming", "sleep", "steak"]

 

we'll give it a name, _stuff.

 

So, _stuff select 0 is "chocolate". Note that the first thing in an array is numbered zero, not one.

 

Now, _x is the bit of the array you have when you go through it one at a time using a loop such as foreach

 

{hint _x} foreach _stuff; will go through the _stuff array one at at time (thats why it's called for each) and hint each one, so this will put out chocolate, then beer, then women and so on.

 

Now, some things are used by the game engine, such as _x, but other like _target,  _caller and _object are made and used by the mission maker, so to know what they are doing is depends on the script they are in

  • Like 2

Share this post


Link to post
Share on other sites


1. my_fnc_add =
2. {
3.     _a = _this select 0;
4.     _b = _this select 1;
5.     _c = _a + _b;          
6.     hint c;
7. };
8. [45,3] call my_fnc_add;
9. //at the upper right corner you see 48


 

Look at that example.

I have made a function called my_fnc_add. This function expects an array with two variables.

So when I call it (line 9.) I have to pass two parameter "[45,3]".

Now the function gets the array you passed. You can address it by "_this" (only inside the function).

So in "my_fnc_add", "_this" contains the array "[45,3]". Now we want to add those two numbers(line 5.).

To do so, we have to select the first number in the array by using "_this select 0". Now "_this select 0" contains 45.

We store it in the variable "_a" for better readabilitry. 

The same goes for the second number using: "_this select 1".

The function would also work using hint ( _this select 0 + _this select 1). But it is harder to read.

 

"...but what I don't understand is what it has to do with "_target, _caller and _object (I think)" 

 

In your example there is propably some function passing/expecting three variables in an array. That's it. 

When you look at the biki you will find a description what _target, _caller and _object or some other variables should be for the function you use.

When you use e.g. "addaction" is passes three variables in an array to a script you launch (_object,_caller,_id).

In this script you can refere to them like this:

 

_obj    = _this select 0; <- this is the object the addaction is attached to (you can also call it _a, _lol, _pinguin or just _obj)

_caller = _this select 1; <- this is the guy who used the action

_id     = _this select 2; <- this is a number the action gets, so you can remove it using: _obj removeAction _id;

 

You get the information about what a function expects and what is returns by reading the biki.

 

 I didn't quite understand what "_x" does as well

 

The "_x" is mainly used in a foreach loop.

 



1. _array = [1,2,3,4,5];
2. {_x = 0} foreach _array;
3. hint _array;
4. //at the upper right corner you see [0,0,0,0,0]


 

foreach expects an array. It loops through all entires of the array. In each loop it saves an entry in _x.

In this example in the first loop it takes the number "1" and saves it in "_x". Then it redefines "_x" as "0" and puts it back in the array.

In the second loop it takes the number "2" and so on.

That's what "_x" is mainly used for.

 

 

I hope I have answered your question. 

Share this post


Link to post
Share on other sites

Thanks a lot! I think i understand now. I had trouble with those 2 variables for long, especially with the fact of them being in the middle of nowhere in a script, i didn't quite understand that but i think i do now. Thanks! :)

Share this post


Link to post
Share on other sites

It is confusing for the new. _x suddenly appears out of nowhere and you're like WTF? Other variables that are similar  are _this and _foreachindex.

 

A lot of this is explained ,though sometimes it assumes more prior knowledge than you seem to have. https://community.bistudio.com/wiki/Variables

 

^^^No insult intended - we all have to start somewhere.

Share this post


Link to post
Share on other sites

I don't take insult from it  :). Thing is i understand variables in other scripting languages such as C++ with integeres (or however you spell them) but in arma "_x" and those other magic variables make it a bit confusing  :mellow:

  • Like 1

Share this post


Link to post
Share on other sites

 

{hint _x} foreach _stuff; will go through the _stuff array one at at time (thats why it's called for each) and hint each one, so this will put out chocolate, then beer, then women and so on.

 

 

Best.  Script.  Evar.

  • Like 1

Share this post


Link to post
Share on other sites

Best.  Script.  Evar.

 

_stuff = ["chocolate", "beer", "women","children","responsibility"]; :P

  • Like 2

Share this post


Link to post
Share on other sites

_stuff = ["chocolate", "beer", "women","children","responsibility"]; :P

 

 

You missed 'steak' and 'sleep'    :lol:

  • Like 1

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

×