Skip to content
This repository has been archived by the owner on Jul 1, 2019. It is now read-only.

Add flag math operations #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add flag math operations #11

wants to merge 1 commit into from

Conversation

SXRWahrheit
Copy link

No description provided.

@@ -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!
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Author

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!

Copy link
Contributor

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.

Copy link
Author

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. 😄

Copy link
Contributor

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.

Copy link
Author

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?
Copy link
Contributor

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:
Copy link
Contributor

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:
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member

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 }

@MusicScore
Copy link
Contributor

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.

@MusicScore
Copy link
Contributor

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. - flag server my_number:<server.flag[my_number].add[2]> vs - flag server my_number:+:2). There's also the technical detail that by using the math actions, you don't have to initialize the flag's value and the "initial" flag value is treated as 0 before the math operation is done. Remember that the expected audience at this point can potentially not know of these details, so being clear on things that seem really basic would do no harm.

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 + and - with another script for * and / (as multiplication and division are also conceptually similar to each other). For example, adding 10 and subtracting 4 from a flag with narrates to demonstrate that 10 was added and 4 was subtracted from the flag's value, resulting in 6. With multiplication/division, you would probably need to have some sort of initial value for the flag since in theory the flag's value would be 0 before the multiplication/division is done. Alternatively, you can use the same flag throughout the section and just make a note as to what the expected flag value is before a particular math operation is done.

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. +, -, *, and \ might go in one table; ++ and -- might go in another.

@MusicScore
Copy link
Contributor

Is there any progress being made on this pull request?

@MusicScore
Copy link
Contributor

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.

@SXRWahrheit
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants