diff --git a/source/docs/basics-of-scripting/memory-flags-and-definitions.rst b/source/docs/basics-of-scripting/memory-flags-and-definitions.rst index 14c3b21..2b6be1e 100644 --- a/source/docs/basics-of-scripting/memory-flags-and-definitions.rst +++ b/source/docs/basics-of-scripting/memory-flags-and-definitions.rst @@ -220,7 +220,72 @@ Of course, you can do a bit more with flags than you can with definitions. 2B. Math With Flags ~~~~~~~~~~~~~~~~~~~ +You can do more than just store raw information with flags - you can also do math! Flag math operations support addition, subtraction, multiplication, and division. The operation you specify will be performed on the value currently stored. Note that this only works for flags with numerical values - if you have stored text on a flag, you cannot use math to change the value! +For example, first we'll use the ``/ex`` command to store a value in a flag: + +.. code:: + + /ex flag server DoSomeMath 10 + +That command will store the value ``10`` in the server flag ``DoSomeMath``. Now, let's do some math! + +.. code:: + + flagmath: + type: world + events: + on player breaks sand: + - flag server DoSomeMath:+:2 + - narrate + +This script will add 2 to the value of the server flag ``DoSomeMath`` when a player breaks sand. Then, it will narrate the value of that flag. Why don't we try subtraction? + +.. code:: + + flagmath: + type: world + events: + on player breaks sand: + - flag server DoSomeMath:-:4 + - narrate + +If you guessed that this script will subtract 4 from the server flag ``DoSomeMath`` each time a player breaks sand, you're correct! You can also do multiplication and division: + +.. code:: + + flagmath: + type: world + events: + on player breaks sand: + - flag server DoSomeMath:*:10 + - narrate + +This script will multiply the server flag ``DoSomeMath`` by 10 each time a player breaks sand. + +.. code:: + + flagmath: + type: world + events: + on player breaks sand: + - flag server DoSomeMath:/:3 + - narrate + +Finally, this script will divide the server flag ``DoSomeMath`` by 3 each time a player breaks sand. + +There are two more options for doing math with flags. You can ``- flag server MyAdditiveFlag:++`` to add 1 to the flag and ``- flag server MySubtractiveFlag:--`` to subtract one from the flag. The addition or subtraction will occur each time the command is run. You can use these commands to easily track simple variables. For example, this script will track zombie deaths: + +.. code:: + ZombieDeathTracker: + type: world + events: + on zombie dies: + - flag server DeadZombies:++ + +With that script, every time a zombie dies, the ``DeadZombies`` server flag will have 1 added to it. + +Using math operations on flags is a quick and easy way to keep track of numerical values and modify them as you need! 2C. Server vs. Player ~~~~~~~~~~~~~~~~~~~~~