Javascript Shared
(Created page with "== General == Shared variables object.<br/> Shared variable lists are available in all scripts.<br/> They are thread safe.<br/> '''NOTE''': Values are stored as plain strings ...") |
(→Methods) |
||
Line 29: | Line 29: | ||
* '''set(name,str)''' | * '''set(name,str)''' | ||
− | + | Set a variable.<br/> | |
Parameters:<br/> | Parameters:<br/> | ||
Line 35: | Line 35: | ||
'''str''' Required variable value<br/> | '''str''' Required variable value<br/> | ||
+ | * '''create(name[,str])''' | ||
+ | Create a variable if does not exist.<br/> | ||
+ | Do nothing if valriable is present in list.<br/> | ||
+ | |||
+ | Parameters:<br/> | ||
+ | '''name''' Required variable name<br/> | ||
+ | '''str''' Optional variable value. Create with empty string if this parameter is not given<br/> | ||
* '''inc(name[,wrap])''' | * '''inc(name[,wrap])''' |
Revision as of 12:05, 3 September 2024
General
Shared variables object.
Shared variable lists are available in all scripts.
They are thread safe.
NOTE: Values are stored as plain strings
Create
Retrieve Yate global
var g = Engine.shared;
var g = new Engine.SharedVars("");
Create separate shared variables list
var g = new Engine.Shared("mylist");
Methods
- get(name)
Retrieve a variable as string
Parameters:
name Required variable name
Return:
Value of the variable
- set(name,str)
Set a variable.
Parameters:
name Required variable name
str Required variable value
- create(name[,str])
Create a variable if does not exist.
Do nothing if valriable is present in list.
Parameters:
name Required variable name
str Optional variable value. Create with empty string if this parameter is not given
- inc(name[,wrap])
Atomically increment a variable as unsigned integer
Parameters:
name Required variable name
wrap Optional value to wrap around at, zero, negative or non numeric disables
Return:
Value of the variable before increment, zero if it was not defined or not numeric
- dec(name[,wrap])
Atomically decrement a variable as unsigned integer
Parameters:
name Required variable name
wrap Optional value to wrap around at, zero, negative or non numeric disables
Return:
Value of the variable after decrement, zero if it was not defined or not numeric
- add(name,value,[,wrap])
Atomically add an unsigned integer value to a variable
Parameters:
name Required variable name
value Required value to add
wrap Optional value to wrap around at, zero, negative or non numeric disables
Return:
Value of the variable before addition, zero if it was not defined or not numeric
- sub(name,value,[,wrap])
Atomically substract an unsigned integer value from a variable
Parameters:
name Required variable name
value Required value to substract
wrap Optional value to wrap around at, zero, negative or non numeric disables
Return:
Value of the variable after substraction, zero if it was not defined or not numeric
- clear(name)
Clear (remove) a variable
Parameters:
name Required variable name
- clearAll()
Clear (remove) all variables in list
Does nothing if the list is the global variables list
- exists(name)
Check if a variable exists
Parameters:
name Required variable name
Return:
Boolean true if variable exists, false otherwise
- getVars([params])
Retrieve list variables
Parameters:
params Optional object with desired behaviour
params properties:
- js_props: Boolean. Return property values as Javascript native types. Default: true
- autonum: Boolean. Try to convert variables to numeric/boolean. Default: false.
Set it when needing to return numbers.
Ignored if not returning Javascript native types - prefix: String. Optional prefix for variables. Retrieve only variables whose name starts with given prefix
- skip_prefix: Boolean. Skip prefix when returned. Default: true
Ignored if prefix is empty
Return:
Object with list variables as properties