Jump to content
Sign in to follow this  
SGJackson

What does "_this select 0" and "_this select 1" do?

Recommended Posts

Hallo all!

My question is simple 'cause i've been taking a look at commands and scripts and i still don't understand what do them do?! This is just for knowing it doesn't help me with anything :P xD

Best Regards, SGJackson!

Share this post


Link to post
Share on other sites

In the following command;

this setPos [(getpos <Object> select 0),(getpos <Object> select 1),(getpos <Object> select 2)]

Select 0 is referring to the X coordinate, select 1 to the Y, and select 2 to the Z axis.

It simply grabs the pre-existing value of the object you choose, for each axis, and applies them as if you physically entered them.

It ranges from select 0 - select 2.

To set this same command, but with a height (Z-Axis) that we determine, so that the object ('this') is placed at the exact position of <Object>, but with a height that we -want- to specify[/i], it would be

this setPos [(getpos <Object> select 0),(getpos <Object> select 1),<Z-Value>]

Hope this helps.

Share this post


Link to post
Share on other sites

In short, _this refers to the array passed to the function. If you run [myunit,"awesome"] execVM "scriptie.sqf" then _this inside the script is [myunit,"awesome"].

select 0/1/2/etc simply selects the element inside the array.

this in the editor often refers to the unit you're editing.

Share this post


Link to post
Share on other sites

exactly what Murklor said, But for the sake of completeness I simply wanted to add that in that case: _this select 0 would be: myunit

and _this select 1 would be: "awesome" (with the "")

the symbol -->> _ before "this" mean that the variable is local to the script (I think? confirmation anyone?)

In short, _this refers to the array passed to the function

that's the key sentence

Share this post


Link to post
Share on other sites
the symbol -->> _ before "this" mean that the variable is local to the script (I think? confirmation anyone?)

Yes.

I just realized I forgot one part about arrays in my guide, an example on how to access values from them. :confused:

I'll explain here and add to the guide later.

As mentioned.

"getPos _dude" returns a position(3d) array with three elements. [x,y,z]

You select the first element with by accessing index zero(0)

_posX = (getPos _dude) select 0;

_posY = (getPos _dude) select 1;

_posZ = (getPos _dude) select 2;

In another example, with an array with more elements.

_someArray = [e1,e2,e3,e4,e5];

Five elements, accessed by index 0 - 4.

i.e.

_fifthElement = _someArray select 4;

_fifthElement is now: e5

(not Leeloo)

_someArray2 = [e1,e2,e3,e4,e5,e6,e7];

Seven elements, accessed by index 0 - 6.

And so on.

Edited by Taurus

Share this post


Link to post
Share on other sites

--Applause--

You guys crapped on my explanation, -AND- taught me something! I love it.

(Taurus, good on you ;P )

Share this post


Link to post
Share on other sites

Guys, i really appreciate this but... I DIDN'T GET A S*** OF WHAT YOU SAID!

Thnx anyway ;)

Best Regards, SGJackson!

Share this post


Link to post
Share on other sites
Guys, i really appreciate this but... I DIDN'T GET A S*** OF WHAT YOU SAID!

Hehe, let me try to confuse you even more. :p

First, what is a array?

It is a list. At least you may think of it as a list. Let us make a sample list:

Forum Members that answered to this post:
- HateDread
- Taurus
- nicolasroger
- Murklor
- Myke
:End of list:

In scripting this would look like this:

_poster_array = [HateDread, Taurus, nicolasroger, Murklor, Myke];

A array is zero-indexed, means counting doesn't start with one but with zero.

Let's assume i want to give nicolasroger a weapon:

_poster_array = [HateDread, Taurus, nicolasroger, Murklor, Myke];
_unit = _poster_array select 2;
_unit addWeapon "NoisyCricket";

So we defined the array in the first line.

We chosed nicolasroger in the second line.

And we added a nice weapon to him in the third.

Thats basically how arrays and the "select" command works.

And about _this inside a script..._this refers to the parameter passed to the script. This might be a single parameter or an array of parameters:

nul = singleVariable execVM "myScript.sqf";

The inside the myScript.sqf you do:

_myVariable = _this;

No select somewhat since we passed a single variable, not an array.

If we pass array:

nul = [these, are, several, variables] execVM [otherScript.sqf";

Then inside the script it could look like this:

_var1 = _this select 0;
_var2 = _this select 1;
_var3 = _this select 2;
_var4 = _this select 3;

Since we passed an array, inside the script we need "select" to read the single variables out of the passed array.

Hope you got it now. If still some things are clear just leave a note. :D

Share this post


Link to post
Share on other sites

1st, i know what an Array is... But of all who posted you where the one that i really like the more xD

PD: Is that your computer progamation in your signature?! It's almost the same that mine!

Best Regards, SGJackson!

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
Sign in to follow this  

×