Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a file to define global variables #64

Closed
MysteryBlokHed opened this issue Jul 5, 2021 · 4 comments · Fixed by #92
Closed

Add a file to define global variables #64

MysteryBlokHed opened this issue Jul 5, 2021 · 4 comments · Fixed by #92
Assignees
Labels
enhancement New feature or request source Affects the project's source
Milestone

Comments

@MysteryBlokHed
Copy link
Owner

Having a variables.toml file or something similar to define global variables could make it easier to let users customize settings. An example of a variables.toml file could look like this:

delay_in_ticks = 500
do_something = true
do_something_else = false

True or false values would be converted to 1 or 0.

The globals could then be referenced in a .databind file by using some preceding character, like a %:

func load
tag load
    var do_something := %do_something
    var do_something_else := %do_something_else
    var delay := %delay_in_ticks
end

func tick
tag tick
    execute if tvar do_something matches 1 run tellraw @a "do_something is true"
    execute if tvar do_something_else matches 1 run tellraw @a "do_something_else is true"
end
@MysteryBlokHed MysteryBlokHed added the enhancement New feature or request label Jul 5, 2021
@MysteryBlokHed MysteryBlokHed added this to the v0.5.0 milestone Jul 7, 2021
@MysteryBlokHed MysteryBlokHed added the source Affects the project's source label Jul 12, 2021
@MysteryBlokHed
Copy link
Owner Author

The % symbol is now used for escaping keywords, so another symbol like $ or & could be used.

@MysteryBlokHed MysteryBlokHed self-assigned this Jul 13, 2021
@MysteryBlokHed MysteryBlokHed modified the milestones: v0.5, v0.6 Jul 18, 2021
@MysteryBlokHed
Copy link
Owner Author

I'm not actually sure that a .toml file will work here since I don't know that there's a way to read a .toml file with unknown values in Rust. A very basic custom config file could be used instead. Something like this:

some_var = 0
another_var = Hello, World!

All values would be treated as text and wouldn't use quotes, since there wouldn't really be a benefit to doing so.

The filename could be something like databind.vars. Something that makes it clear it's Databind-related without using the .databind extension (since it wouldn't make sense here).

@MysteryBlokHed
Copy link
Owner Author

With the % character being used to escape keywords and the $ character used in macro variables, another character would have to be used for global variables. Something like & should work (eg. say &some_var), since I don't believe it's used anywhere else. It would probably be replaced in source files similar to how macros replace their arguments. This would make it impossible to escape them, however, but that shouldn't be a problem; unless the & is followed by variable defined in the databind.vars file, it will be ignored.

@MysteryBlokHed
Copy link
Owner Author

I'm not actually sure that a .toml file will work here since I don't know that there's a way to read a .toml file with unknown values in Rust. A very basic custom config file could be used instead. Something like this:

some_var = 0
another_var = Hello, World!

All values would be treated as text and wouldn't use quotes, since there wouldn't really be a benefit to doing so.

The filename could be something like databind.vars. Something that makes it clear it's Databind-related without using the .databind extension (since it wouldn't make sense here).

Using a .ini file would probably be ideal instead of writing a custom parser just for a single file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request source Affects the project's source
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant