Creating a dynamic variable
-
Start by getting the dynamic variable item in the Variables inventory.
In order to access the Variables inventory, right click the Variables
item. It is an iron ingot item placed at the 9th slot of your hotbar,
as shown in the image below:
-
Now, the Variables inventory should be open. Click the
Dynamic Variable item shown in the images below:
-
You will be given the Dynamic Variable item in your inventory.
-
Now, you need to name the dynamic variable! You can name
the dynamic variable by sending a message to the chat while
holding the dynamic variable item. The message sent will be
the name of the dynamic variable.
-
These are the rules of dynamic variable names:
- It cannot start with â/â, unless minecraft modifications is used.
- The length of the variable name can only be at most 256 characters
long, unless minecraft modifications is used. - Unsupported symbols in minecraft will not show properly in
dynamic variables.
-
Extra notes
-
You can use placeholders in the dynamic variable names.
This can be used to create player-specific dynamic variables
or entity-specific dynamic variables. Below is the list of
some of the placeholders you can have in a dynamic variable name.- %player%
- Main playerâs name in the event
- Main player refer to the player that triggered the event
- Usable in most player events
- %default%
- Default/First playerâs name in the event
- Usable in most player events
- %random%
- Random playerâs name
- Only picks a random player that is
online on the world - Usable in every player event, loops
and functions
- %killer%
- Killer playerâs name
- Usable in player events categorized as âCombatâ
- %damager%
- Damager playerâs name
- Usable in player events categorized as âCombatâ
- %shooter%
- Shooter playerâs name
- Usable in player events categorized as âCombatâ
- %player%
-
If your dynamic variable contains at least one of these placeholders
above, it will be converted into the appropriate name if applicable.For example,
- AtomSeis is the player that triggered the event.
- Thus, dynamic variable named â%player%_sui-chanâ
would be converted to âAtomSeis_sui-chanâ
- Narokbar killed AtomSeis, Narokbar is the player that
triggered the event. - Therefore, dynamic variable named â%killer%_isBestâ
would be converted to âNarokbar_isBestâ
-
Where in the variable name you place the placeholder does not
matter! Furthermore, you can have multiple placeholders in the
dynamic variable name. It will be replaced regardless.More examples:
- AtomSeis killed Narokbar, AtomSeis is the player that
triggered the event with Narokbar being the victim. - This would result in a dynamic variable named
âcommon_%killer%%victim%â being converted to
âcommon_AtomSeisNarokbarâ
- Narokbar shot AtomSeis using a bow, Narokbar is the
player that triggered the event with AtomSeis being the
victim. - Hence, a dynamic variable named
â%shooter%_common%victim%â will be converted into
"Narokbar_commonAtomSeis
- AtomSeis killed Narokbar, AtomSeis is the player that
-
Lastly, by sneaking and right click while holding the dynamic variable,
will set it to âSAVEDâ property, meaning it will be saved regardless
if the player left the world, or the world closed down.
Particularly useful if you wish to create a statistic variable
-
With that, you had made a dynamic variable, complete with the name!
Now, you can move onto modifying or setting the value of the dynamic variables.
Modifying and setting the value of dynamic variables
-
You can modify, or set the value of a dynamic variable in the set
variable block, as shown in the image:
-
Set Variable block has five categories:
-
General
Methods in General category:
You can set the value of a dynamic variable using Set Variable (=)
Set Random Value will randomly select one of the values provided
and set it as the dynamic variable value -
Numbers
Methods in Numbers category:
By using Set to Sum (+), you can set a dynamic variable value
to a sum of two or more values, refer to the image below:Set to Difference (-) allows you to set a dynamic variable value to a
difference between two number variables values, dynamic variables
values with number values or a combination of both. Better
explained in the image given below:Increment Variable (+=) allows you to increment a dynamic variable
value that is a number by a specific amount you set.In another words, you can add a number to a dynamic variable by a
specific amount you set. Since itâs an incrementation method, you
canât use a text variable value here and incrementing with a value
after the decimal point. Number with a value before and after the
decimal point will be rounded down before being added to the
dynamic variableDecrement Variable (-=) functions similarly to
Increment Variable (+=). It allows you to decrement a
dynamic variable by a specific amount you set.In another words, it allows you to subtract a specified number
from a dynamic variable. Similar to Increment Variable (+=),
text variable value cannot be used in this method and decrementing
with a value after the decimal point. Number with a value before and
after the decimal point will be rounded down before being subtracted
from the dynamic variable -
Text
Methods in Text category:
Combine Texts is a better alternative to Set to Sum (+)
if you want to set a combination of text variables values
to a dynamic variable.It allows you to combine one or more text values and then
set it as a dynamic variable value. You can also combine
numbers and dynamic variables values together with text
values.Number values provided will be converted to text and
then combined with other values. It also remove decimal
point if numbers after the decimal point is 0.Parse Number, like the method name suggests, will set a
dynamic variable value to a number variable, parsed from
a text variable when possible. The description provides
a good example: -
Location
Methods in Location category:
Get Value From Location can let you acquire a specific element
from a location variable or a dynamic variable containing location
value. You can acquire one of these elements:- X Coordinates
- Y Coordinates
- Z Coordinates
- Yaw
- Pitch
The acquired value will then be saved to the dynamic variable placed.
Get The Distance Between Locations
You can acquire the distance between two locations using this
method. Be noted however, the distance include the first location
but does not include the second location.Set Location Values
You can increment, or replace each element in location variable.
If you want to subtract a number from an element, place in negative
numbers. Leave empty if you donât need to change an element
number
-
That should sum up some of the Set Variable block methods you can use to
modify or set a dynamic variable! You can find more methods in Set Variable
block however, try to explore these!
If you have made it this far, congratulations!
With dynamic variables, you can create games with better features. I hope this could help, best of luck to everyone trying! See you next time, have a good day!