• 0
TroyT

_this variable?

Question

I'm just looking into the basics of SQF coding so I can analyze some scripts.   I keep seeing the 

_this

variable called, but never see it initialized.  Is this a special variable, or what does it typically refer to?

Example:

Spoiler

/********************************************************************
 * sneak_server
 * file: sneak_server\code\SneakCustoms_change_skin.sqf
 * Author: Sneak
 * [email protected]
 * This extension is licensed under the Arma Public Licence
 ********************************************************************/
private ["_originalTextures", "_paid", "_playerMoney", "_skinPrice", "_tmp", "_currentTimestamp", "_expiringDate", "_currentVehicleNetId", "_sessionId", "_player", "_skinClass", "_currentVehicle", "_currentVehicleId", "_missionPath", "_jpg", "_page", "_pageSize","_currentVehicleIdAndSkin", "_found", "_skinTextures", "_groupsActive", "_liteVersion", "_validUIDs", "_dbEntry"];
diag_log format ["[SNEAK_CUSTOMS]change_skin called"];
_sessionId = _this select 0;
_currentVehicleNetId = (_this select 1);
_currentVehicle = objectFromNetId _currentVehicleNetId;
_skinClass = _this select 2;
_playerNetId = _this select 3;
_skinPrice = _this select 4;
_originalTextures = _this select 5;
_availableForGroup = _this select 6;
_player = objectFromNetId _playerNetId;
_paid = false;
_playerMoney = _player getVariable ["ExileMoney", 0];

 

 



I've been reading the BI scripting pages but would welcome any better recommendations on sqf scripting info.

 

Edited by TroyT

Share this post


Link to post
Share on other sites

3 answers to this question

  • 0

https://community.bistudio.com/wiki/this

  • In Scripts/Functions: The given arguments that were passed by a call, exec, execVM or spawn.
    For the arguments in scripts executed by mission-made actions or Event Handlers, check addAction and Event Handlers.
  • In Addons' config files: An array with the current object as its first (and only) element.
  • In Addons' custom UserActions: Unit that is activating the action.
  • In Dialogs: An array with the current control as its first (and only) element (only available during runtime).

Rough explanation but, in the the script you posted.  _this would refer to the variables or objects passed to the script in an exec call.  For example:

[_player] ExecVM "/scripts/yourscriptname.sqf";

_sessionId = _this select 0;

Would be the first element of the array passed starting with 0.

Share this post


Link to post
Share on other sites
  • 0
19 hours ago, TroyT said:

I'm just looking into the basics of SQF coding so I can analyze some scripts.   I keep seeing the 


_this

variable called, but never see it initialized.  Is this a special variable, or what does it typically refer to?

Example:

  Hide contents


/********************************************************************
 * sneak_server
 * file: sneak_server\code\SneakCustoms_change_skin.sqf
 * Author: Sneak
 * [email protected]
 * This extension is licensed under the Arma Public Licence
 ********************************************************************/
private ["_originalTextures", "_paid", "_playerMoney", "_skinPrice", "_tmp", "_currentTimestamp", "_expiringDate", "_currentVehicleNetId", "_sessionId", "_player", "_skinClass", "_currentVehicle", "_currentVehicleId", "_missionPath", "_jpg", "_page", "_pageSize","_currentVehicleIdAndSkin", "_found", "_skinTextures", "_groupsActive", "_liteVersion", "_validUIDs", "_dbEntry"];
diag_log format ["[SNEAK_CUSTOMS]change_skin called"];
_sessionId = _this select 0;
_currentVehicleNetId = (_this select 1);
_currentVehicle = objectFromNetId _currentVehicleNetId;
_skinClass = _this select 2;
_playerNetId = _this select 3;
_skinPrice = _this select 4;
_originalTextures = _this select 5;
_availableForGroup = _this select 6;
_player = objectFromNetId _playerNetId;
_paid = false;
_playerMoney = _player getVariable ["ExileMoney", 0];

 

 



I've been reading the BI scripting pages but would welcome any better recommendations on sqf scripting info.

 

https://community.bistudio.com/wiki/this

When you call something, the things before the call are passed to the script.

["somshit"] call some_fnc;
you can access ["someshit"] by doing _this, and to access "someshit" you can do _this select 0

  • Like 1

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.