-
Notifications
You must be signed in to change notification settings - Fork 0
scopedvariables
This module introduces scoped variables, allowing variables to be namespaced automatically by script, folder (package), or a custom scope string.
It provides:
- A configurable default scope per script
- A
scoped variableexpression that transparently rewrites variable paths - Full support for get / set / add / remove / delete / reset
- Correct handling of local, ephemeral, and list variables
All scoping is implemented by rewriting variable names internally.
A scoped variable is a normal Skript variable whose storage key is prefixed with a scope.
Instead of:
set {count} to 1
you get:
scoped::<scope>::count
Scopes prevent collisions between scripts, folders, or logical modules while still using Skript’s variable system.
Each script can define a default scope that is used whenever no explicit scope is provided.
set default scope for scoped variables in current script to
current folder
current package
current script
folder <string>
package <string>
<script>
| Option | Resulting Scope |
|---|---|
current script |
Script file name |
current folder / current package
|
Script’s parent folder relative to /scripts
|
folder <string> / package <string>
|
Custom folder/package scope |
<script> |
Explicit script scope |
set default scope for scoped variables in current script to current folder
set default scope for scoped variables in current script to folder "economy"
set default scope for scoped variables in current script to script "main.sk"
If no default scope is set, the script name is used.
scoped [variable] %variable% [within|from|by
%-script%
| current folder
| current package
]
This expression rewrites the backing variable name based on:
- The variable being accessed
- The resolved scope
- Variable modifiers (local, ephemeral, list)
If no explicit scope is provided:
- Use the script’s default scope, if set
- Otherwise, use the current script name
If an explicit scope is provided:
| Clause | Scope Used |
|---|---|
within <script> |
That script |
current folder / current package
|
Script’s parent folder |
Scoped variables preserve all Skript variable semantics.
set {_x} to 1
set scoped {_x} to 5
→ stored under:
_scoped::<scope>::x
set {-temp} to 3
set scoped {-temp} to 9
→ stored under:
-scoped::<scope>::temp
set {data::a} to 1
set scoped {data::*} to 2
→ stored under:
scoped::<scope>::data::*
The scoped variable expression supports all standard variable operations:
- get
- set
- add
- remove
- remove all
- delete
- reset
set scoped {count} to 1
add 5 to scoped {count}
broadcast scoped {count}
delete scoped {playerdata::*}
set scoped {_local} to "hello"
set scoped {coins} within current folder to 100
set scoped {coins} within script "bank.sk" to 250
Internally, variables are rewritten as:
[prefix]scoped::<scope>::<variable-name>[:: *]
Where:
-
prefixis:-
_for local variables -
-for ephemeral variables
-
-
<scope>is the resolved scope string -
::*is appended for list variables
This is an implementation detail and should not be relied upon directly.
- Scoped variables are not a new variable type — they are rewritten normal variables
- Scope resolution depends on the script’s file path
- Moving scripts between folders may change scope values
- Local and ephemeral behavior matches native Skript semantics
- Variable names are resolved at runtime using the current event
- Script modularization
- Library-style Skript files
- Avoiding global variable collisions
- Folder-based namespaces
- Shared state with controlled visibility