global.set 40
Set a global variable that can be referenced from any script and by any player in the room
Return value
Return Type | Description |
---|---|
void | This function doesn't return anything |
Parameters
Parameter | Type | Description |
---|---|---|
1 | any | A variable to store. Accepted types: bool, float, int, string |
2 | string | Identifier to get the stored value |
Examples
Example 51
-- save a value "100" on a global variable
global.set(100, "some_stored_integer")
-- save a value "true" on a global variable
global.set(true, "some_stored_bool")
-- save a value "hello!" on a global variable
global.set("hello!", "some_stored_text")
Example 183
-- You can't set a vehicle directly as a global net-syncronized variable, but you can set it's unique Id
local veh_id = somevehicle.getUniqueId() -- get unique id of the vehicle (net synched)
global.set(veh_id, "target_vehicle") -- set the id as global var
-- Then another script or another client can do
local veh_id = global.get("target_vehicle") -- retrieve the id of the vehicle
local findsomeveh = er2.findVehicle(veh_id) -- acquire the vehicle by it's Id
-- Note: you can do the same with soldiers with soldier.getUniqueId() and er2.findSoldier()