Class ExpressionScope
java.lang.Object
net.citizensnpcs.api.ai.tree.expr.ExpressionScope
A variable scope for expression evaluation with lazy binding support. Variables are only computed when accessed and
cached for the evaluation cycle.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidBinds a lazily-evaluated variable.Creates a child scope that inherits from this scope.Gets a variable value, computing lazy bindings if necessary.Gets the memory instance for this scope or parent scope if not present.getNPC()Gets the NPC for this scope or parent NPC if not present.Gets all variable names currently in scope.booleanChecks if a variable exists in this scope or parent scopes.voidRemoves a variable from the scope.voidClears cached lazy values.voidSets an eager (immediate) value for a variable.voidSets the memory instance for this scope.voidSets the NPC for this scope.
-
Constructor Details
-
ExpressionScope
public ExpressionScope() -
ExpressionScope
-
-
Method Details
-
bind
Binds a lazily-evaluated variable. The supplier is called only when the variable is first accessed, and the result is cached for the evaluation cycle. -
createChild
Creates a child scope that inherits from this scope. -
get
Gets a variable value, computing lazy bindings if necessary. Lookup order: eager values -> cached lazy values -> compute lazy -> parent scope- Parameters:
name- the variable name- Returns:
- the value, or null if not found
-
getMemory
Gets the memory instance for this scope or parent scope if not present. -
getNPC
Gets the NPC for this scope or parent NPC if not present. -
getVariableNames
Gets all variable names currently in scope. -
has
Checks if a variable exists in this scope or parent scopes.- Parameters:
name- the variable name
-
remove
Removes a variable from the scope. -
resetCache
public void resetCache()Clears cached lazy values. Call this between evaluation cycles to allow lazy values to be recomputed with fresh data. -
set
Sets an eager (immediate) value for a variable. -
setMemory
Sets the memory instance for this scope. -
setNPC
Sets the NPC for this scope.
-