Entity::getVariable: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__


{{SharedFunctionJS}}


Retrieves the custom data from the entity.
Retrieves a server side custom data from the entity.
 
{{ServersideJsFunction}}


{{JSContainer|
{{JSContainer|
Line 10: Line 11:
entity.getVariable('variableName');
entity.getVariable('variableName');
</pre>
</pre>
=== Required Arguments ===
*{{Required}}'''entity''': {{RageType|Object}}
*{{Required}}'''name''': {{RageType|String}}


==Example==
==Example==
This example will retrieve the data from the variable 'veh' that is assigned to the player
This example will retrieve the data from the variable 'veh' that is assigned to the player
{{SharedCode|
{{ServersideCode|
<pre>
<pre>
let veh = player.getVariable('veh');
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}`);
});
</pre>
</pre>
</div>
}}
}}
}}
}}

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