MysteryBlokHed / databind

Expand the functionality of Minecraft Datapacks.
https://databind.rtfd.io/en/stable
GNU General Public License v3.0
4 stars 0 forks source link

Add option to create local variables #147

Open MysteryBlokHed opened 1 year ago

MysteryBlokHed commented 1 year ago

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