GlobalVars
com.jsmacrosce.jsmacros.core.library.impl.FGlobalVars
Stores named Java values shared by scripts in this JsMacros runtime. Values remain until removed or the game session ends; loading another profile does not clear them. Typed getters return null for a missing value or a value of another type; they do not coerce.
js
GlobalVars.putInt("sessions", 0);
const next = GlobalVars.incrementAndGetInt("sessions");
print(`session ${next}`);Accessible in scripts via the global GlobalVars variable.
Fields
globalRaw
Live backing map. Direct writes bypass the guest-object check in putObject(String, Object); typed getters return
null for values of other types. Counter and toggle operations use atomic map computations.Methods
decrementAndGetInt
Decrements the integer under
name and returns the new value. A missing key is set to and returns -1; a non-integer value is unchanged and returns null. The read and update are atomic.Parameters:
name: key to decrement
Returns: the value after decrement,
-1 if absent, or null if not an integergetAndDecrementInt
Decrements the integer under
name and returns its previous value. A missing key is set to -1 and returns 0; a non-integer value is unchanged and returns null. The read and update are atomic.Parameters:
name: key to read and decrement
Returns: the value before decrement,
0 if absent, or null if not an integergetAndIncrementInt
Atomically increments the integer under
name and returns its previous value. An absent key is set to 1 and returns 0; a non-integer value is unchanged and returns null. Unlike incrementAndGetInt(String), this returns the value before incrementing. print(`first call: ${GlobalVars.getAndIncrementInt("hits")}`);
print(`second call: ${GlobalVars.getAndIncrementInt("hits")}`);Parameters:
name: the name to read and increment
Returns: the value before the increment,
0 for a name that held nothing, or null if the name holds something that is not an integergetBoolean
getDouble
getInt
getObject
getRaw
Returns the live backing map, not a copy. Direct writes bypass the guest-object check in putObject(String, Object).
Returns: the live backing map
getString
getType
Returns the stored value's type name:
"Int", "String", "Double", "Boolean", or "Object"; returns null if the name holds nothing. "Object" covers all other stored Java types, including numbers stored under a different numeric type; typed getters do not coerce them. GlobalVars.putInt("count", 1);
GlobalVars.putDouble("ratio", 0.5);
GlobalVars.putString("name", "notch");
GlobalVars.putBoolean("enabled", true);
print(`${GlobalVars.getType("count")} and ${GlobalVars.getType("ratio")}`);
print(`${GlobalVars.getType("name")} and ${GlobalVars.getType("enabled")}`);
GlobalVars.putObject("raw", JavaUtils.createArrayList());
print(GlobalVars.getType("raw")); // "Object"Parameters:
name: the name to look up
Returns: one of the five type names above, or
null if the name holds nothingincrementAndGetInt
Increments the integer under
name and returns the new value. A missing key is set to 1 and returns 1; a non-integer value is unchanged and returns null. The read and update are atomic. Unlike getAndIncrementInt(String), this returns the value after incrementing.Parameters:
name: the name to increment
Returns: the value after the increment,
1 for a name that held nothing, or null if the name holds something that is not an integerputBoolean
putDouble
putInt
putObject
Stores a Java object under
name. Guest objects are rejected with an AssertionError; any existing value is replaced regardless of type. GlobalVars.putObject("lastResult", JavaUtils.createHashMap());
print(GlobalVars.getType("lastResult")); // "Object"Parameters:
name: the name to store undero: the Java object to store
Returns:
o, the same object that was storedputString
remove
toggleBoolean
Atomically toggles the boolean under
name and returns the resulting value. A missing key is set to true; a non-boolean value is left unchanged and yields null.Parameters:
name: key to toggle
Returns: the new value, or
null if the existing value is not boolean