-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a file to define global variables (#92)
Adds a vars.ini file to define global replacements.
- Loading branch information
1 parent
7de1b0d
commit 48f59dd
Showing
11 changed files
with
179 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
target/ | ||
testing/ | ||
_build/ | ||
databind.toml |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Global Vars | ||
=========== | ||
|
||
You can define global variables with a file called ``vars.ini`` in the project root. | ||
Keys and values aren't put in a section of the ``.ini``, they're just in the file. For example: | ||
|
||
.. code-block:: ini | ||
name=World | ||
This defines a global variable ``name`` that can be used in your code. | ||
|
||
Using Global Vars | ||
----------------- | ||
|
||
To use a global variable in your code, use an ``&`` symbol followed | ||
by the variable name. Like this: | ||
|
||
.. code-block:: databind | ||
say Hello, &name! | ||
Which, with the ``vars.ini`` defined above, becomes: | ||
|
||
.. code-block:: mcfunction | ||
say Hello, World! | ||
Instances of ``&varname`` are directly replaced, meaning that | ||
escaping them with a ``%`` symbol doesn't work. This means that | ||
the following code: | ||
|
||
.. code-block:: databind | ||
say Hello, %&name! | ||
Just becomes: | ||
|
||
.. code-block:: databind | ||
say Hello, %World! | ||
``%World`` is effectively the same as ``World``, so the ``%`` symbol | ||
won't appear in the compiled output. | ||
|
||
When to use | ||
----------- | ||
|
||
Global variables are useful to let users more easily configure aspects | ||
of your datapack. This does mean that the project must be recompiled | ||
whenever the configuration is changed, and that users must have Databind | ||
downloaded to use the project. If you are only configuring number values, | ||
eg. an amount of time to wait for something, then it might be easier for | ||
people using your datapack to have a ``config.mcfunction`` file somewhere in the | ||
project that sets scoreboard values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,6 @@ Contents: | |
cli.rst | ||
config.rst | ||
macros.rst | ||
global_vars.rst | ||
folder_structure.rst | ||
examples.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
4 changes: 4 additions & 0 deletions
4
tests/resources/test_global_vars/src/data/test/functions/main.databind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
func main | ||
say &var1 | ||
tellraw @a "&var2" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var1=Variable 1 | ||
var2 = Variable 2 |