-
Notifications
You must be signed in to change notification settings - Fork 3
Add flag math operations #11
base: master
Are you sure you want to change the base?
Conversation
@@ -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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line doesn't seem to obey the 120-visible-character limit. Of course it doesn't matter to the frontend user, but for backend users who will be seeing the source and editing it (hopefully), they need to be able to read the backend without having to scroll horizontally.
|
||
.. code:: | ||
|
||
/ex flag server DoSomeMath 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to put a space between DoSomeMath
and 10
?
Also, generally speaking since most things involving an assigned ID tend to be case insensitive, I think it's a good idea to use all lowercase names, plus underscores.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, yes insofar as I am more used to using define
than flag
and I probably should have checked before committing.
I use CapitalCase or whatever in my internal scripts for clarity, but if you want all-lowercase that's fine!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For internal/personal use, CapitalCase is fine. It's just that for a public script or something, it should be encouraged to not use CaptialCase since names tend to be case insensitive anyways, so it's less of a hassle to just use all lowercase plus underscores. Saves the theoretical trouble of naming two definitions "HelloWorld" and "HELLOworld" and them overriding each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that is good to know! I look forward to a design document, and hopefully we can augment it over time by way of me attempting contributions. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A technical detail:
Shouldn't you put that command in a script container? I know it may seem redundant, but a task or world script may better frame the command to the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was a good example of being able to set flags with the command, but sure that would work too.
- flag server DoSomeMath:+:2 | ||
- narrate <server.flag[DoSomeMath]> | ||
|
||
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment for line 223.
- flag server DoSomeMath:-:4 | ||
- narrate <server.flag[DoSomeMath]> | ||
|
||
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment for line 223.
|
||
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment for line 223.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional commentary: I don't feel that this section is very clear on how the :++
and :--
actions work. For example, it's not clarified that they don't take a value, and that they naturally only add/subtract 1.
Additionally, flags are already introduced as a way to store values in a more persistent manner, so there's no need to reiterate that they can track simple values. Just note that these mathematical operators can be used to directly change the value of the flag, given that the flag's value is a number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
is increment, --
is decrement.
Addition/Subtraction are higher order math. x + y
is basically repeat y { x++ }
Similar to how multiplication like x * y
is the next order above addition repeat y { answer += x }
In addition to all of the comments above, it seems that none of the code blocks are marked as figures. They seem to be at least more important than a simple syntax explanation, so I would like them all be marked as figures. Also, thanks for mentioning to me via Discord that I don't have a guidelines page for contributors here. Sorry for that! Will add something to that effect as soon as possible. |
Overall, this does a good job as a quick primer for doing math with flag actions, though I feel that there are more parts you can be clearer on. For example, you should emphasize that the flag actions allow you to directly modify the flag's value without having to use a math tag and reassigning the flag's value (e.g. It may be a wise idea to condense some of the scripts for simplicity. Since addition and subtraction are conceptually similar, perhaps there can be one script for Also, I encourage you to use tables! It's a good way to essentially summarize all of the relevant information in a table so that it's easier for users to quickly refer back to it if they're in the middle of writing a script and, for some reason, forget the list of mathematical flag actions they can use. |
Is there any progress being made on this pull request? |
It has been nearly two months since I last asked, and I have seen no progress being made, nor any attempt at communication of progress (in the form of questions or directly telling me what has been done). Please update your PR with any changes you have made recently within the next week, or I will assume that this PR is no longer being maintained. This will, in turn, result in me closing this pull request and doing the job myself. |
I wasn't sure if you planned to continue work on this project, given recent events, and I didn't want to exacerbate anything. I'm glad to hear you still want to pursue it, and I'll have time to finish this PR this weekend. |
No description provided.