-
Notifications
You must be signed in to change notification settings - Fork 38
Math
Modulo functions use the % and %= operators to perform. % simply puts the first number modulo the second number, no variable assignment. %= works very similar to % except the result is assigned to the variable you are doing the %= on.
var percent = 3;
print(percent % 2); // 1
print(percent); // 3
var percentEquals = 3;
print(percentEquals %= 2); // 1
print(percentEquals); // 1Addition uses the +, +=, and ++ operators to perform. + simply adds the two, no variable assignment. += works very similar to + except the result is assigned to the variable you are doing the += on. ++ increments the variable you are using it on by one.
var plus = 3;
print(plus + 1); // 4
print(plus); // 3
var plusEquals = 3;
print(plusEquals += 1); // 4
print(plusEquals); // 4
var plusPlus = 3;
print(plusPlus++); // 4
print(plusPlus); // 4Addition can be used to concatenate strings. Use + or += to add two strings together.
var helloWorld = "Hello World";
print("My variable has the value of: " + helloWorld + "!"); // My variable has the value of: Hello World!Subtraction uses the -, -=, and -- operators to perform. - simply subtracts the two, no variable assignment. -= works very similar to - except the result is assigned to the variable you are doing the -= on. -- decrements the variable you are using it on by one.
var minus = 3;
print(minus - 1); // 2
print(minus); // 3
var minusEquals = 3;
print(minusEquals -= 1); // 2
print(minusEquals); // 2
var minusMinus = 3;
print(minusMinus--); // 2
print(minusMinus); // 2Multiplication uses the * and *= operators to perform. * simply multiplies the two, no variable assignment. *= works very similar to * except the result is assigned to the variable you are doing the *= on.
var star = 3;
print(star * 2); // 6
print(star); // 3
var starEquals = 3;
print(starEquals *= 2); // 6
print(starEquals); // 6Multiplication can also be used to multiply elements in arrays.
var myArray = [0];
myArray *= 4;
print(myArray); // [0,0,0,0] (An Array with four times the )Division uses the / and /= operators to perform. / simply divides the two, no variable assignment. /= works very similar to / except the result is assigned to the variable you are doing the /= on.
var slash = 3;
print(slash / 2); // 1.5
print(slash); // 3
var slashEquals = 3;
print(slashEquals /= 2); // 1.5
print(slashEquals); // 1.5Exponents use the ^ and ^= operators to perform. ^ simply puts the first number to the power of the second, no variable assignment. *= works very similar to * except the result is assigned to the variable you are doing the *= on.
var caret = 3;
print(caret ^ 2); // 9
print(caret); // 3
var caretEquals = 3;
print(caretEquals ^= 2); // 9
print(caretEquals); // 9There are many math-based built-in functions in RoboScript. Things that do not have a clear symbol to perform the operation use these built-in functions. Here is a list of them.
sin(#); // Performs a sine function with the number inputted.
cos(#); // Performs a co-sine function with the number inputted.
tan(#); // Performs a tangent function with the number inputted.
ceil(#); // Returns the least whole number that is greater than the number inputted; Rounding up the number inputted.
floor(#); // Returns the greatest whole number that is less than the number inputted; Rounding down the number inputted.
min(#,#); // Returns the lesser number of the two.
max(#,#); // Returns the greater number of the two.