Jump to content
Sign in to follow this  
Laksekjønn

How to enable global var in SMS?

Recommended Posts

Smart Mobile code insight exposes some global vars and queues utilities. In SMS there are local & cookie storage objects which expose similar functionality to global vars. I'm just interesting in using this global var through the units. How do you enable these global vars?

CleanupGlobalVars;

var backup = SaveGlobalVarsToString;

WriteGlobalVar('test', 'hello world');
WriteGlobalVar('testNum', 123);
WriteGlobalVar('testFloat', 2.5);
WriteGlobalVar('testBool', True);

LoadGlobalVarsFromString(backup);

ReadGlobalVar('test');
ReadGlobalVar('testNum');
ReadGlobalVar('testFloat');
ReadGlobalVar('testBool');

Background information:

======================

Global Var: is accessed through the ReadGlobalVar(name) and WriteGlobalVar(name, value) functions. They allow reading and writing a value by name, in an in-memory dictionary. Read & write operations are atomic.

While they’re quite self-sufficient on their own, you’ll usually want to access them through a minimal wrapper functions that’ll handle namespaces.

Here is the complete list of Global var functions:

ReadGlobalVar(name) : reads the variable of given name, returns Null if not defined
ReadGlobalVarDef(name, default) : reads the variable of given name, returns default if not defined
TryReadGlobalVar(name, var value) : attempts to read variable of given name, if defined places the value in value and returns True, otherwise returns False

WriteGlobalVar(name, value, [expiration]) : writes value into the variable of given name, with an optional auto-expiration (in seconds)

IncrementGlobalVar(name, delta = 1) : adds delta to the variable of given name and returns the resulting value

DeleteGlobalVar(name) : deletes the variable of given name

CleanupGlobalVars(filter = ‘*’) : delete variables matching the specified filter (wildcards ‘*’ and ‘?’ are supported). Memory is compacted if relevant. An empty string as filter will essentially just run a compaction operation.

GlobalVarNames : returns an array of string that holds the names of all variables

SaveGlobalVarsToString : returns a streamed persistence of all global vars

LoadGlobalVarsFromString : loads a streamed persistence of all global vars

 

Global Queues: are named chains of values which can be used both as a LIFO and FIFO queues. Writing or reading from a queue is thread-safe and atomic.

While they’re quite self-sufficient on their own, you’ll usually want to access them through a minimal wrapper functions that’ll handle namespaces.

Here is the complete list of Global Queues functions:

GlobalQueuePush(name, value) : adds value at the tail of the queue of given name
GlobalQueueInsert(name, value) : adds value at the head of the queue of given name
GlobalQueuePull(name, var value) : removes a value from the head of the queue of given name, places it in value and returns True. If the queue is empty, returns False
GlobalQueuePop(name, var value) : removes a value from the tail of the queue of given name, places it in value and returns True. If the queue is empty, returns False
GlobalQueueLength(name) : returns the length of the queue of given name
CleanupGlobalQueues : delete queues matching the specified filter (wildcards ‘*’ and ‘?’ are supported)


 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×