Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Add option to create local variables #147

@MysteryBlokHed

Description

@MysteryBlokHed

Currently, variables declared with the var keyword are all stored as scoreboard under the --databind username. This works fine for variables that should be available everywhere, but can cause problems when someone only wants variables to exist in a certain context.

While there aren’t “local scoreboards” to use, local variables could be affixed with a randomly-generated series of characters, similar to how while loops’ functions are created. Local variables would be accessible from anywhere in the file where they’re declared.

I’m not sure whether it’d be a better idea to create new keywords for things that affect variables (i.e. local versions of tvar, gvar, etc.), or to allow local variables to take precedence over global ones and abstract away the differences.

Example (local variables take precedence):

func main
tag load
    local i := 10
    while tvar i matches 1..
        tellraw @a "i is greater than 0"
        var i -= 1
    end
end

Example (new keywords for local vars):


func main
tag load
    local i := 10
    while tlvar i matches 1..
        tellraw @a "i is greater than 0"
        local i -= 1
    end
end

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions