Entity::setVariable: Difference between revisions
MrPancakers (talk | contribs) (Cleaned up) |
No edit summary |
||
| (7 intermediate revisions by 4 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> | <pre> | ||
| Line 10: | Line 16: | ||
entity.setVariable({name1: value1, name2: value2}); | entity.setVariable({name1: value1, name2: value2}); | ||
</pre> | </pre> | ||
=== Required Arguments === | |||
*{{Required}}'''entity''': {{RageType|Object}} | |||
*{{Required}}'''name''': {{RageType|String}} | |||
*{{Required}}'''value''': {{RageType|Any}} | |||
==Example== | ==Example== | ||
This binds the vehicle to the player | This binds the vehicle to the player | ||
{{ServersideCode| | |||
<pre> | <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> | </pre> | ||
}} | |||
}} | |||
} | |||
== See More == | == See More == | ||
{{Entity_functions}} | {{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);