Difference between revisions of "Entity::setVariable"

From RAGE Multiplayer Wiki
Jump to navigation Jump to search
m
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
__TOC__
 +
 
{{ServersideJsFunction}}
 
{{ServersideJsFunction}}
 +
 
Set custom data to an entity.
 
Set custom data to an entity.
  
 +
{{JSContainer|
 
==Syntax==
 
==Syntax==
 
<pre>
 
<pre>
Line 10: Line 14:
 
entity.setVariable({name1: value1, name2: value2});
 
entity.setVariable({name1: value1, name2: value2});
 
</pre>
 
</pre>
 +
 +
=== Required Arguments ===
 +
*'''entity''': {{RageType|Object}}
 +
*'''name''': {{RageType|String}}
 +
*'''value''': {{RageType|Any}}
  
 
==Example==
 
==Example==
Line 29: Line 38:
 
});
 
});
 
</pre>
 
</pre>
 +
}}
 
}}
 
}}
  

Revision as of 12:37, 2 December 2019

Server-Side
Function

Js.png JavaScript



Set custom data to an entity.

JavaScript Syntax
Jslogo.png

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);


This is an example of setting multiple variables to a player which is not implemented and does not work (yet)

Server-Side
player.setVariable({
  name: 'Player',
  age: 20
});


See More