-
Notifications
You must be signed in to change notification settings - Fork 0
8. JSON In Line Math Expressions
Still under construction
There are terms that might be confusing. So here are some synonyms and explanations:
- "returns" / "yields" / "results in": The result of an operation or function.
- "parameter" / "argument": The values you pass to an operation or function.
- Names may not start with digits (
0-9) - Names may only contain letters (
A-Zanda-z), digits (0-9) and underscores (_)
-
int: Integers, eg.0,7,-87. -
double: Floating point numbers, eg.0.0,1.7,-43.467,2. -
vec3: 3-dimensional vector made of 3doubleelements representing any position or motion in a world. -
boolean: Boolean (logical) values, eg. eithertrueorfalse. -
tag: NBT compound tags (see Minecraft wiki). -
string: A sequence of characters, eg.'hello','ABCdef123_','Let us also do some Spaces!!'.
These are the possible type conversions (eg. whenever a double is required you can also put in a value of type int, but not the other way around):
-
int->double -
int->string -
double->string -
boolean->string
E.g. how to make type values with text:
-
int: Just type the integer, eg.0,7,-87. -
double: Type the floating point number using a., eg.0.0,1.7,-43.467,2. -
vec3: Use thevec3function mentioned below, eg.vec3(2, 4, 6). -
boolean: Type the logical values, eg. eithertrueorfalse. -
tag: To make a new compound tag use thenew_tagsupplier function mentioned below and populate that using theput_nbt_*functions, eg.put_nbt_int(new_tag(), 'my_key', 7)makes a new tag and attaches the integer7with the keymy_keyresulting in{"my_key": 7}. -
string: Write the sequence of characters wrapped by'characters, eg.'hello','ABCdef123_','Let us also do some Spaces!!'.
These tables represent all binary operations defined by types. If two operants have different types the resulting type is looked up and the non-matching operant is converted according to the type conversions definition. Eg. Adding a double and a int together will convert the later into a double first and then sum these two up.
Any operation between 2 types not being defined here means that it is also not defined in the system. Attempting such an operation will yield no result.
+ / -
|
int |
double |
|---|---|---|
int |
int |
double |
double |
double |
double |
+ / -
|
vec3 |
|---|---|
vec3 |
vec3 |
The + operation also works with strings. Whenever a string is added together with another string, these are concatenated, eg. 'abc' + 'def' results in the string 'abcdef'.
* / /
|
int |
double |
vec3 |
|---|---|---|---|
int |
int |
double |
vec3 |
double |
double |
double |
vec3 |
vec3 |
vec3 |
vec3 |
Dividing by 0 yields no result.
Works only with the int type. Remainder by 0 yields no result.
All of these comparison operators allow you to compare 2 values. They always yield a boolean as result depending on whether the comparison is true or false (eg. 0 <= 1 is obviously true, 'AB' == 'CD' is false because they are not equal). The comparison operators are available for the following types:
-
==(equality):int,double,vec3,boolean,string -
!=(inequality):int,double,vec3,boolean,string -
>(greater than):int,double -
>=(greater than or equal):int,double -
<(less than):int,double -
<=(less than or equal):int,double
&& |
false |
true |
|---|---|---|
false |
false |
false |
true |
false |
true |
&& |
false |
true |
|---|---|---|
false |
false |
true |
true |
true |
true |
This is a unary operation where you write the ! symbol in front of the operant.
!true -> false!false -> true
This is a ternary operation (3 operants) which yields the 2nd or 3rd operant depending on if the 1st operant is true or not:
condition ? value_if_true : value_if_false
Examples:
-
a > b ? a : bwill always return the bigger value ofaorb(this is the same as themaxfunction). -
flag ? var : 12will returnvarifflagistrue, otherwise returns12.
You can also stack these:
a ? b : (c ? d : e)
All functions are explained here. This is to be read as function_name(argument_types) -> result_type:
-
function_name: Name of the function -
argument_types: The amount of arguments and their types -
result_type: Every function yields a single result with a defined type
-
pi() -> double: The value of PI.pi() -> 3.14159265359...
-
tag() -> tag: Create a new empty nbt compound tag. -
sqrt2() -> double: The value of the square root of 2.sqrt2() -> 1.41421356237...
-
random_int() -> int: Any possible integerxwith-2147483648 <= x <= 2147483647(2 to the power of 32 different values).random_int() -> -67
-
random_double() -> int: Any possible doublexwith0 <= x < 1.random_double() -> 0.78125
-
random_uuid() -> string: A random UUID.random_uuid() -> '139AA4B1-D4EC-4A01-9BA0-18E5C32BFCF2'
-
new_tag() -> tag: A new and empty NBT compound tag.
-
round(double) -> int: Rounds thedoublenumber towards the closestintnumber with.5being rounded up.round(1.2) -> 1round(2.5) -> 2round(3.7) -> 4round(-5.5) -> -5round(-1.9) -> -2round(6.0) -> 6
-
floor(double) -> int: Rounds down thedoublenumber to anintnumber.floor(1.2) -> 1floor(2.5) -> 2floor(3.7) -> 3floor(-5.5) -> -6floor(-1.9) -> -2floor(6.0) -> 6
-
ceil(double) -> int: Rounds up thedoublenumber to anintnumber.ceil(1.2) -> 2ceil(2.5) -> 3ceil(3.7) -> 4ceil(-5.5) -> -5ceil(-1.9) -> -1ceil(6.0) -> 6
-
sqrt(double) -> double: Calculates the square root of adoublenumber. This number must be positive.sqrt(9.0) -> 3.0sqrt(2) -> 1.41421356237...
-
get_x(vec3) -> double: The x-coordinate of thevec3vector. -
get_y(vec3) -> double: The y-coordinate of thevec3vector. -
get_z(vec3) -> double: The z-coordinate of thevec3vector. -
length(vec3) -> double: Calculates the length of thevec3vector. -
normalize(vec3) -> vec3: Normalizes thevec3vector (yields the argumentvectordivided by its length). -
sin(double) -> double: Calculates the sinus of thedoubleangle, in radians. -
cos(double) -> double: Calculates the cosinus of thedoubleangle, in radians. -
asin(double) -> double: Calculates the asinus (inverse sinus, or sin-1) of thedoubleangle, in radians. -
acos(double) -> double: Calculates the acosinus (inverse cosinus, or cos-1) of thedoubleangle, in radians. -
to_radians(double) -> double: Converts thedoubleangle from radians to degrees. -
to_degrees(double) -> double: Converts thedoubleangle from degrees to radians. .uuid_from_string(string) -> string: Takes any string as seed for the random generator to generate a new UUID from. Calling this method any amount of times with the same parameter always yields the same UUID as result. -
next_int(int) -> int: Generates a random positive integer up to but excluding the value of the parameter, eg. ifxis the parameter andyis the result then0 <= y < x.next_int(10) -> 3
-
min(int, int) -> int/min(double, double) -> double: Gives you the lower value of the 2 arguments.min(1, 2) -> 1min(2, 1) -> 1min(-5, -2) -> -5min(-7, -7) -> -7
-
max(int, int) -> int/max(double, double) -> double: Gives you the higher value of the 2 arguments.max(1, 2) -> 2max(2, 1) -> 2max(-5, -2) -> -2max(-7, -7) -> -7
-
nbt_contains(tag, string) -> boolean: Returnstrueif the given tag contains a value of the givenstringname, otherwise returnsfalse. -
get_nbt_int(tag, string) -> int: Returns theintthat is on the given tag with the givenstringname. -
get_nbt_double(tag, string) -> int: Returns thedoublethat is on the given tag with the givenstringname. -
get_nbt_boolean(tag, string) -> boolean: Returns thebooleanthat is on the given tag with the givenstringname. -
get_nbt_compound_tag(tag, string) -> tag: Returns thetagthat is on the given tag with the givenstringname. -
get_nbt_string(tag, string) -> string: Returns thestringthat is on the given tag with the givenstringname. -
get_nbt_uuid(tag, string) -> string: Returns thestringthat is on the given tag with the givenstringname in form of a UUID. -
get_nbt_vec3(tag, string) -> vec3: Returns thevec3that is on the given tag with the givenstringname in form of a list of typedouble.
-
vec3(double, double, double) -> vec3: Constructs avec3made of the 3doublearguments, with the firstdoublebecoming the x-coordinate, the seconddoublebecoming the y-coordinate, and the thirddoublebecoming the z-coordinate. -
put_nbt_int(tag, string, int) -> tag: Makes a copy of the giventagand puts the giveninton it under the givenstringname then returns this new tag. -
put_nbt_double(tag, string, double) -> tag: Makes a copy of the giventagand puts the givendoubleon it under the givenstringname then returns this new tag. -
put_nbt_boolean(tag, string, boolean) -> tag: Makes a copy of the giventagand puts the givenbooleanon it under the givenstringname then returns this new tag. -
put_nbt_compound_tag(tag, string, boolean) -> tag: Makes a copy of the giventag(1st parameter) and puts the giventag(2nd parameter) on it under the givenstringname then returns this new tag. -
put_nbt_string(tag, string, string) -> tag: Makes a copy of the giventagand puts the givenstring(2nd parameter) on it under the givenstringname (3rd parameter) then returns this new tag. -
put_nbt_uuid(tag, string, string) -> tag: Makes a copy of the giventagand puts the givenstring(2nd parameter) on it under the givenstringname (3rd parameter) in form of a UUID then returns this new tag. -
put_nbt_vec3(tag, string, vec3) -> tag: Makes a copy of the giventagand puts the givenvec3on it under the givenstringname in form of a list of typedoublethen returns this new tag.
More specifics about this compiler.
- Binds strongest
()-
-/! -
*///% -
+/- -
>/>=/</<= -
==/!= &&||?:- Binds weakest
This is the exact definition of the compiler, for those interested in it.
-> expression
variable := ( letter | "_" ) { letter | digit | "_" } .
value := digit { digit } [ "." { digit } ] .
function_call := letter { letter | digit | "_" } "(" [ expression { "," expression } ] ")" .
expression := conditional .
conditional := disjunction [ "?" disjunction ":" disjunction ] .
disjunction := conjunction { "||" conjunction } .
conjunction := comparison { "&&" comparison } .
comparison := relation { ( "==" | "!=" ) relation } .
relation := sum { ( ">" | ">=" | "<" | "<=" ) sum } .
sum := product { ( "+" | "-" ) product } .
product := factor { ( "*" | "/" | "%" ) factor } .
factor := [ "-" | "!" ] ( variable | value | "(" expression ")" | function_call ) | "'" string "'" .