-
Notifications
You must be signed in to change notification settings - Fork 4
Getting Started
- Run 7Sharp
- Type
editin the shell to open the editor - Type code
- Click edit
- Type
runinto the shell to run the code. Some beta builds will print A LOT of debug output, you can ignore this.
- No arguments >
name(); - 1 argument >
name(123); - 2 arguments >
name(123, 456); - etc.
Example:
write("Hi!");
name = value;
Examples
x = 2 + 2;
name = read();
y = "x is " + x;
z = name;
w = 42 * 1337;
c = 3 / 2;
modulusTest = c % 2;The loop loop runs code a specified number of times.
loop (n) {
// code to be run n times
// the function getLoopIndex() will get the current index of the current loop loop.
// Think about it as the "i" variable in C’s for loop.
// It starts at 0, and then is incremented after each run of the loop
}getLoopIndex is used to get the index of a loop loop. When given no argument, it will get the index of the current loop loop. If 1 is passed in, it will get the index of the loop loop outside of the current loop loop. If 2 is passed in it will get the index of the loop loop outside of the loop loop outside of the current loop loop, and so on. Passing in a double will cause an error, same thing with neagive values.
while (condition) {
// this code will run while condition is true
}break; - exit the current loop
Example:
loop (5) {
i = getLoopIndex();
if (i == 3) {
break;
}
write(i);
}
/*
Output:
0
1
2
*/continue; - skip the rest of the code in the current loop, and start the next iteration of the loop
loop (5) {
i = getLoopIndex();
if (i == 2) {
continue;
}
write(i);
}
/*
Output:
0
1
3
4
*/// just an if
if (a) {
// will run if a is true
}
// if else
if (b) {
// code here
} else {
// this will run is b is false
}
// else if
if (c) {
// code
} else if (d) {
// will run if c is false but d is true
}
// you can add as many else ifs as you want
else {
// this is optional, but this will run if none of the other if else’s above run
}To include libraries, you use the import statement.
Syntax: import "name";
name will point to either file (if no extension is provided it will assume .7slib), or a system library.
-
write(text)- outputtextfollowed by a new line -
writeraw(text)- outputtext, NO NEW LINE! -
getLoopIndex(n = 0)- get the index of the currentloop(n) {}loop -
sin(x)cos(x)tan(x)asin(x)acos(x)atan(x)atan2(x, y)- standard trig functions, all are in radians. -
sqrt(x)- return the square root ofx -
pow(x, n)- returnxto the power ofn -
deg2rad(degrees)rad2deg(radians)- Degrees <--> Radians conversion -
sleep(ms)- wait formsmiliseconds -
len(arrayOrString)- get the length ofarrayOrString -
chars(string)- get an array of the characters ofstring -
arrayAdd(array, value)- addvalueto the end ofarray -
arrayRemove(array, index)- remove the value inarrayatindex -
toString(obj)- convertobjto a string. If given an array, it will return"Array [contents, go, here]" -
double(obj)- convertobjto a double -
int(obj)- convertobjto an int -
fgColor(color)andbgColor(color)- change the foreground (text) color and background color of the console.- Ex:
fgColor(YELLOW); write("Hello!");will printHello!in yellow - Note: both functions will accept numbers 0 to 15 as input as well!
- Color list:
- BLACK
- BLUE
- CYAN
- DARK_BLUE
- DARK_CYAN
- DARK_GRAY
- DARK_GREEN
- DARK_MAGENTA
- DARK_RED
- DARK_YELLOW
- GRAY
- GREEN
- MAGENTA
- RED
- WHITE
- YELLOW
- Ex:
-
resetColor()- reset the colors of the console
-
random.sys-
nextInt(min, max)- get a random integer betweenminandmax -
nextDouble(min, max)- get a random double (64-bit floating point) betweenminandmax -
next()- get a random 32-bit integer -
setSeed(seed)- set RNG seed toseed
-
-
io.sys-
readFile(path)- get a read stream to file atpath -
writeFile(path)- get a write stream to file atpath -
close(stream)- closestream, use this to clean up resources used by stream. Not calling this could cause a memory leak. -
readByte(stream)- read a byte fromstream -
readLine(stream, encoding = "utf8")- read a line of text fromstreamusing encodingencoding, default encoding isutf8. Supported encodings:ascii,utf8 -
readText(stream, count, encoding = "utf8")- readcountcharacters fromstreamusing encodingencoding, default encoding isutf8. -
writeByte(stream, value)- write the bytevaluetostream -
writeText(stream, text, encoding = "utf8")- writetextto stream using encodingencoding, default encoding isutf8. -
writeLine(stream, text, encoding = "utf8")- writetextto stream, followed by a new line using encodingencoding, default encoding isutf8.
-
7Sharp has the ability for users to create and use community created libraries, all within 7Sharp itself.
To import a custom library, do import "custom library";
7Sharp will search for a file called
custom library.7slibIf found it will import all of its functions! After that, you can use any function in that library!
To make a custom library, do the following:
- Put your code into the editor (type
editin the shell). - Type
export "file path"into the shell. Now you should have a 7slib file at that path! (It's a zip file, so you can open it by changing the extension to.zip)
To define a custom function, do the following:
function name(arguments, seperated, by, commas, this, is, optional, though) {
// code
}If you want your function to exit early or output a value (e.g. to put in a variable), then you use return.
To exit the function early, just do return;
To return a value, use return value;
function sum(a, b) {
return a + b;
}
x = sum(2, 2);
write(x); // Should output "4"function doStuff(x) {
write("Doing stuff!");
if (x == 3) {
return;
}
write("x is not 3! x is: " + x);
}
doStuff(5); // Outputs "Doing stuff!" and "x is not 3! x is: 5"
doStuff(3); // Outputs "Doing stuff!"