FluffScript Syntax Variables: // Declare a variable var myVarName; // Initialize a variable var myVarName = 5; // Assign to an existing variable myVarName = 10; // increase/decrease existing variable myVarName = myVarName += 1; myVarName = myVarName -= 1; // If a variable isn't going to change its value, it is best to use the keyword 'const' /* * Constants cannot be redeclared * Constants cannot be reassigned * Constants must be assigned a value when they are declared */ // Example: const PI = 3.141592653589793; PI = 5; // This will give an error User Input: /* Unlike regular asynchronous input methods used in JS, FluffScript uses synchronous input. readLine, readInt, readFloat, and readBoolean are non-blocking functions that can be used in combination with the `break` keyword to receive input asynchronously. */ var name = break readLine("What's your name?"); print(“Nice to meet you, " + name); Math: // Operators: + Addition - Subtraction * Multiplication / Division ** Exponentiation % Modulus (Remainder) () Parentheses (For order of operations) // Examples var z = x + y; var w = x * y; // Increment (add one) x++ // Decrement (subtract one) x-- // Increment (add number) x += 10 // Decrement (subtract number) x -= 10 // Shortcuts x = x + y; x += y; x = x - y; x -= y; x = x * y; x *= y; x = x / y; x /= y; // Exponentiation var squared = 5 ** 2; print(squared); // prints out 25 // Modulus var z = 10 % 4 // 2 * 4 = 8; 10 - 8 = 2 print(z) // prints out: 2 // Absolute value var abs = abs(x); // Square root var sqrt = sqrt(x); // Rounding // round() can be used to round numbers var pi = 3.14; var roundedPi = round(pi); print(roundedPi); // prints out: 3 var goldenRatio = 1.618; var roundedGoldenRatio = round(goldenRatio); print(roundedGoldenRatio); // prints out: 2 // Floor Division // floor() can be used to perform floor // division. With floor division, only the // integer portion of the quotient is returned. // For example, 5/2 is 2.5, but with floor division, // the result is 2 and the .5 is discarded. var result = floor(5/2); print(result); // prints out: 2 // Geometry // Note input is in radians, not degrees sin(radians); // Returns value between -1 and 1 cos(radians); // Returns value between -1 and 1 tan(radians); // Returns value Functions: // Functions can take in values, called parameters. // The function below takes in a parameter called // 'input' and prints it. function printText(input) { print(input); } // Functions can also return a value. // The function below takes in a value, // adds two to it, and returns it. function addTwo(number) { return number + 2; } Control Structures: if(BOOLEAN_EXPRESSION){ // code to execute if true } if(BOOLEAN_EXPRESSION){ // code if true } else { // code if false } // You can use else if if you have multiple // conditions, but only one should happen. if(condition_1){ } else if(condition_2) { } else if(condition_3) { } else { } // You can always write these using nested // if/else. For example: if(condition_1){ // code here runs if condition 1 is true } else { if(condition_2){ // if condition 2 is true } else { // and here if condition 2 is false } } if(x < 0){ print("x is negative."); } if(x > 0){ print("Positive number”); } else { print(“Negative number”); } if(fluffballs == 10){ print(“10!”); } Looping: repeat(5){ /* Repeat code betweeen the brackets 5 times. */ } while(boolean expression){ /* Repeat code betweeen brackets while * 'boolean expression' is true */ } Delays: // waits 1000 miliseconds sleep(1000); Data structures: Only arrays will be implemented because I’m too lazy LOL… // Create an empty array var arr = []; // Create an array with values var arr = [1, 2, 4]; // An array can have any type var arr = [4, "hello", x]; // Access an element in an array var elem = arr[1]; var firstElem = arr[0]; // Set an element in an array arr[4] = 9; // Looping over an array var i = 0; var arr = [1, 2, 4]; repeat(10){ i += 1; var cur = arr[i]; // process cur } // length of an array var length = arr.length; // Add to an array arr.push(elem); // Remove last element from array var last = arr.last(); // Finding the index of an element in a list var index = arr.indexOf(5); // Remove an element from a list at index i arr.remove(i)