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) |
||
(2 intermediate revisions by one user not shown) | |||
Line 29: | Line 29: | ||
* '''set(name,str)''' | * '''set(name,str)''' | ||
− | + | Set a variable.<br/> | |
Parameters:<br/> | Parameters:<br/> | ||
'''name''' Required variable name<br/> | '''name''' Required variable name<br/> | ||
'''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/> | ||
Line 112: | Line 121: | ||
'''params''' properties: | '''params''' properties: | ||
* '''js_props''': Boolean. Return property values as Javascript native types. Default: true | * '''js_props''': Boolean. Return property values as Javascript native types. Default: true | ||
− | * '''autonum''': Boolean. Try to convert variables to numeric/boolean. Default: false.<br/>Set it when needing to return | + | * '''autonum''': Boolean. Try to convert variables to numeric. Default: false.<br/>Set it when needing to return numbers.<br/>Ignored if not returning Javascript native types |
+ | * '''autobool''': Boolean. Try to convert variables to boolean. Default: false.<br/>Set it when needing to return boolean values.<br/>Ignored if not returning Javascript native types | ||
* '''prefix''': String. Optional prefix for variables. Retrieve only variables whose name starts with given prefix | * '''prefix''': String. Optional prefix for variables. Retrieve only variables whose name starts with given prefix | ||
* '''skip_prefix''': Boolean. Skip prefix when returned. Default: true<br/>Ignored if prefix is empty | * '''skip_prefix''': Boolean. Skip prefix when returned. Default: true<br/>Ignored if prefix is empty |
Latest revision as of 12:08, 3 September 2024
[edit] General
Shared variables object.
Shared variable lists are available in all scripts.
They are thread safe.
NOTE: Values are stored as plain strings
[edit] Create
Retrieve Yate global
var g = Engine.shared;
var g = new Engine.SharedVars("");
Create separate shared variables list
var g = new Engine.Shared("mylist");
[edit] 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. Default: false.
Set it when needing to return numbers.
Ignored if not returning Javascript native types - autobool: Boolean. Try to convert variables to boolean. Default: false.
Set it when needing to return boolean values.
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