WebExeBuilder Documentation

setVar

Category: Variable Management

Namespace: web.variables.setVar

Description

Sets a persistent variable that survives application restarts. Variables are stored in memory and can be saved to disk.

Syntax

const success = await web.variables.setVar('username', 'JohnDoe');

Parameters

  • varName (required) - Variable name (key) — positional first argument
  • varValue (required) - Variable value (stored as string) — positional second argument

Returns

Promise<boolean> - Returns a promise that resolves with true if successful, false otherwise

Examples

Simple example

const success = await web.variables.setVar('theme', 'dark');

if (success) {
    console.log('Variable saved');
}

Store user preferences

// Save multiple user preferences
await web.variables.setVar('language', 'en');

await web.variables.setVar('fontSize', '14');

await web.variables.setVar('autoSave', 'true');

console.log('Preferences saved');

Store JSON data

// Store complex data as JSON string
const userData = {
    name: 'John Doe',
    email: 'john@example.com',
    role: 'admin'
};

await web.variables.setVar('currentUser', JSON.stringify(userData));

Use Cases

  • Store user preferences and settings
  • Save application state between sessions
  • Cache frequently used data
  • Store user-specific configuration
  • Maintain session data across restarts

Notes

  • Variables persist in memory during application runtime
  • Use saveVariables() to persist to disk for survival across restarts
  • All values are stored as strings - convert as needed
  • Variable names are case-sensitive
  • Overwrites existing variable if name already exists
  • Variables are stored in a dictionary (FGlobalVariables)