Entity::setVariable: Difference between revisions
(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: | ||
__TOC__ | |||
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== | ||
< | <pre> | ||
// To set one variable at a time | |||
entity.setVariable(name, value); | entity.setVariable(name, value); | ||
</ | |||
// 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== | ||
{{ | This binds the vehicle to the player | ||
< | {{ServersideCode| | ||
<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); | ||
</ | </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 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);