Entity::getVariable: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__


'''Function''': Gets a custom data from an entity.


Retrieves a server side custom data from the entity.
{{ServersideJsFunction}}
{{JSContainer|
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">
<pre>
value entity.getVariable(name); // Returns null if key 'name' does not exist.
entity.getVariable('variableName');
</syntaxhighlight>
</pre>
 
=== Required Arguments ===
*{{Required}}'''entity''': {{RageType|Object}}
*{{Required}}'''name''': {{RageType|String}}


==Example==
==Example==
{{Shared}}
This example will retrieve the data from the variable 'veh' that is assigned to the player
<syntaxhighlight lang="javascript">
{{ServersideCode|
// Supposed you want to get a vehicle you bound with a player
<pre>
let veh = player.getVariable('veh');
mp.events.addCommand('setNick', (player, nickname) => {
</syntaxhighlight>
  player.setVariable('oldNick', player.name);
  player.name = nickname;
  player.setVariable('newNick', nickname);
  console.log(`Player[${player.id}] Changed nick from ${player.getVariable('oldNick')} to ${player.name}`);
});
</pre>
}}
}}
 
== See More ==
{{Entity_functions}}
 
[[Category:Entity API]]
[[Category:Server-side Function]]

Latest revision as of 17:17, 12 September 2024


Retrieves a server side custom data from the entity.

Server-Side
Function

 JavaScript



JavaScript Syntax

Syntax

entity.getVariable('variableName');

Required Arguments

  • *entity: Object
  • *name: String

Example

This example will retrieve the data from the variable 'veh' that is assigned to the player

Server-Side
mp.events.addCommand('setNick', (player, nickname) => {
  player.setVariable('oldNick', player.name);
  player.name = nickname;
  player.setVariable('newNick', nickname);
  console.log(`Player[${player.id}] Changed nick from ${player.getVariable('oldNick')} to ${player.name}`);
});


See More