Entity::setVariable: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "__NOTOC__ '''Function''': Sets a custom data into an entity. ==Syntax== <syntaxhighlight lang="javascript"> entity.setVariable(name, value); </syntaxhighlight> ==Example==...")
 
No edit summary
 
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__
__TOC__


'''Function''': Sets a custom data into an entity.
Set custom data to an entity. These variables are visible only server side.<br>
See [[Entity::setVariables]] to set multiple variables in bulk.
<br><br>


{{ServersideJsFunction}}
{{JSContainer|
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">
<pre>
// To set one variable at a time
entity.setVariable(name, value);
entity.setVariable(name, value);
</syntaxhighlight>
 
// To set multiple variables at a time.
entity.setVariable({name1: value1, name2: value2});
</pre>
 
=== Required Arguments ===
*{{Required}}'''entity''': {{RageType|Object}}
*{{Required}}'''name''': {{RageType|String}}
*{{Required}}'''value''': {{RageType|Any}}


==Example==
==Example==
{{ServerSide}}
This binds the vehicle to the player
<syntaxhighlight lang="javascript">
{{ServersideCode|
// Supposed you're trying to bind a vehicle to a player, you can do this:
<pre>
let veh = mp.vehicles.new(vehName, player.position);
let veh = mp.vehicles.new(vehName, player.position);
player.setVariable('veh', veh);
player.setVariable('veh', veh);
</syntaxhighlight>
</pre>
}}
 
}}
 
== See More ==
{{Entity_functions}}
 
[[Category:Entity API]]
[[Category:Server-side Function]]

Latest revision as of 17:15, 12 September 2024

Set custom data to an entity. These variables are visible only server side.
See Entity::setVariables to set multiple variables in bulk.

Server-Side
Function

 JavaScript



JavaScript Syntax

Syntax

// To set one variable at a time
entity.setVariable(name, value);

// To set multiple variables at a time.
entity.setVariable({name1: value1, name2: value2});

Required Arguments

  • *entity: Object
  • *name: String
  • *value: Any

Example

This binds the vehicle to the player

Server-Side
let veh = mp.vehicles.new(vehName, player.position);
player.setVariable('veh', veh);



See More