Skip to content

Commit bd0c0c9

Browse files
Moderockygitbook-bot
authored andcommitted
GitBook: [#26] No subject
1 parent f6bbfd5 commit bd0c0c9

File tree

6 files changed

+280
-1
lines changed

6 files changed

+280
-1
lines changed

.gitbook/assets/image (1).png

20.2 KB
Loading

.gitbook/assets/image.png

15.8 KB
Loading

SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Table of contents
22

33
* [🎶 Introduction to ByteSkript](README.md)
4+
* [Getting Started](readme/getting-started.md)
45

56
## Structures
67

@@ -24,6 +25,7 @@
2425
* [Variables](structures/expressions/variables.md)
2526
* [Simple Expressions](structures/expressions/simple-expressions.md)
2627
* [I/O Expressions](structures/expressions/i-o-expressions.md)
28+
* [Events](structures/events.md)
2729

2830
## namespaces
2931

namespaces/skript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ These functions provide basic utilities, mostly related to the JDK `System` clas
2121
| `get_class(name)` | Returns the `Class` object with the provided name, or nothing if it doesn't exist. |
2222
| `get_atomic_literal(object)` | Returns the given atomic variable as a regular object to be stored in a value variable. |
2323
| `current_time_millis()` | Returns the current time in milliseconds as a `Long`. Useful for comparing time passed. |
24-
| `line_separator()` | Returns the system's line-separator character (`\n` or `\r\n` etc.) |
24+
| `line_separator()` | Returns the system's line-separator character ( or `\r` etc.) |
2525
| `nano_time()` | Returns the system nanosecond time as a `Long`. Useful for comparing time passed. |
2626
| `hashcode(object)` | Returns the provided `Integer` hash code of an object. |
2727
| `strict_equals(object, object)` | Performs a strict `ACMP` equals check on the objects, returning `true` if they reference the same object in memory or `false` if not. |

readme/getting-started.md

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
---
2+
description: >-
3+
A beginner's introduction to using ByteSkript's basic features and running
4+
scripts.
5+
---
6+
7+
# Getting Started
8+
9+
ByteSkript allows scripts to be run in a standalone environment from the command-line. Some versions may be attached to other applications (e.g. a Minecraft server) but for simplicity this guide assumes you are using the basic version.
10+
11+
### Installing ByteSkript
12+
13+
The latest ByteSkript version can be downloaded from the [GitHub Releases](https://github.com/Moderocky/ByteSkript/releases) page.
14+
15+
There are **three** main executable Jars here.
16+
17+
* **SkriptLoader**: loads and runs user-created scripts.\
18+
This is the best option for creating and running scripts locally.
19+
* **SkriptJarBuilder**: compiles scripts into an executable jar file.\
20+
This is useful for building shareable versions of the program with no dependencies.
21+
* **SkriptCompiler**: compiles scripts into raw classes.\
22+
This is designed for language developers - these files are not directly executable.
23+
24+
This guide is written for using **SkriptLoader**.
25+
26+
{% hint style="success" %}
27+
**Make sure you have** [**Java**](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) **installed.**
28+
29+
ByteSkript always runs on the latest Java version (currently 17.)
30+
{% endhint %}
31+
32+
### Setting up Your Environment
33+
34+
The first time you run ByteSkript it will create all of the necessary folders and files for you.
35+
36+
1. Place the downloaded `SkriptLoader.jar` into an empty folder. 
37+
2. Run the Jar file with `java -jar path/to/SkriptLoader.jar`.\
38+
Windows users can do this through command prompt or by [creating a clickable bat file](https://stackoverflow.com/questions/394616/running-jar-file-on-windows).\
39+
Mackintosh/Linux users can do this through terminal or by [creating a clickable shell file](https://coderedirect.com/questions/534005/script-to-run-jar-file-on-mac-os-x).
40+
41+
This should create **four** folders next to the ByteSkript jar.
42+
43+
The `skript/` folder is the most important.
44+
45+
| Folder | Description |
46+
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
47+
| `skript` | This is where you put the scripts you write. Any `.bsk` file in this directory will be run. |
48+
| `libraries` | This is where you can install third-party syntax libraries. Place the Jar/class in this folder. |
49+
| `resources` | This is for adding extra text/data files that you want to package inside your compiled scripts. If you are using **SkriptLoader** you do not need to use this folder. |
50+
| `compiled` | If you are using **SkriptCompiler** or **SkriptJarBuilder** the compiled output will go here. |
51+
52+
### Writing Your First Script
53+
54+
Any file with a name ending in `.bsk` in the `skript/` folder will be seen and loaded by ByteSkript.
55+
56+
{% hint style="info" %}
57+
While a basic app like Notepad++ or TextEdit is sufficient, a code-editing app like GitHub's [Atom](https://atom.io), Microsoft's [VSCode](https://code.visualstudio.com) or JetBrains [IntelliJ](https://www.jetbrains.com/idea/) may be more useful.
58+
{% endhint %}
59+
60+
Start by creating a new script file called `myscript.bsk` in the `skript/` folder. You can open this file in your editor app.
61+
62+
For testing, we can start by writing a simple trigger for the `on [script] load` [event](../structures/members/events.md).
63+
64+
![](../.gitbook/assets/image.png)
65+
66+
This `on load` event will be run when your script is loaded, but never again.
67+
68+
```clike
69+
on load:
70+
trigger: // the code to be run goes inside triggers
71+
print "hello" // prints hello to the command-line
72+
```
73+
74+
Our `trigger:` section needs to be indented inside the `on load:` event. This is to tell ByteSkript that the trigger belongs to this event.
75+
76+
{% hint style="success" %}
77+
You can indent using tabs **or** spaces (2, 4, 8, etc.) but **not** a mixture of both!
78+
{% endhint %}
79+
80+
The `print "hello"` [effect](../structures/effects/generic-effects.md#print) will print a line to the system output (command-line.) You can read more about this and other effects in the [documentation](../structures/effects/generic-effects.md#print).
81+
82+
Once you've saved your `myscript.bsk` file, you can run it using the [**SkriptLoader**](getting-started.md#running-your-scripts).
83+
84+
You should see a "hello" output in your console.
85+
86+
{% code title="java -jar SkriptLoader.jar" %}
87+
```log
88+
hello
89+
90+
```
91+
{% endcode %}
92+
93+
By default, the program will run until you kill it by closing the console window. On a UNIX terminal, `CTRL + C` will end the program.
94+
95+
If we want it to end automatically, we can add an `exit program` [effect](../structures/effects/flow-control-effects.md#exit-program) to our trigger.
96+
97+
![](<../.gitbook/assets/image (1).png>)
98+
99+
This effect will end the JVM process. If we re-run the **SkriptLoader** now, it will automatically terminate after printing `hello` to the console.
100+
101+
#### Introducing Another Effect
102+
103+
Let's make our program a little more complex and introduce the [wait](../structures/effects/generic-effects.md#wait-for) effect.
104+
105+
```clike
106+
on load:
107+
trigger:
108+
print "hello"
109+
wait 3 seconds // waits for three seconds
110+
print "I waited for you"
111+
exit program
112+
```
113+
114+
In this version, the program will wait for three seconds before printing the second output. Nothing will happen during this time.
115+
116+
#### Introducing a Variable
117+
118+
Currently our program is very simple. To add more complex behaviour, we will need to introduce [variables](../structures/expressions/variables.md).
119+
120+
Variables are in-program containers to store data. There are currently four types, but for now we will use the most basic one.
121+
122+
Variables use a `{var_name}` pattern. The name can contain alphaneumeric characters and `_` but **must** start with an `a-z` letter character.
123+
124+
Instead of directly printing `"hello"` we can try introducing a variable.
125+
126+
```clike
127+
on load:
128+
trigger:
129+
set {var} to "hello" // sets the variable
130+
print {var} // gets the variable value
131+
exit program
132+
```
133+
134+
For more information about using variables see [here](../structures/expressions/variables.md).
135+
136+
#### Adding a Function
137+
138+
Rather than writing all of our code inside the load event `trigger`, we can organise it by breaking it up into separate **functions**.
139+
140+
We can add a new function to the same `myscript.bsk` file.
141+
142+
```clike
143+
function my_function:
144+
trigger:
145+
print "This was run from a function!"
146+
```
147+
148+
The `function ...` declaration goes on the root level of the file and is **not** indented.
149+
150+
Our whole file should now look like this.
151+
152+
{% code title="myscript.bsk" %}
153+
```clike
154+
on load:
155+
trigger:
156+
set {var} to "hello"
157+
print {var}
158+
exit program
159+
160+
function my_function:
161+
trigger:
162+
print "This was run from a function!"
163+
```
164+
{% endcode %}
165+
166+
Currently, our function won't do anything since nothing is running it.
167+
168+
We can call it using the [run effect](../structures/effects/flow-control-effects.md#run) with `run my_function()`. &#x20;
169+
170+
{% code title="myscript.bsk" %}
171+
```clike
172+
on load:
173+
trigger:
174+
set {var} to "hello"
175+
print {var}
176+
run my_function() // my_function will be run here
177+
print "a function was run" // this happens after the function finishes
178+
exit program
179+
180+
function my_function:
181+
trigger:
182+
print "this was run from a function"
183+
```
184+
{% endcode %}
185+
186+
When running our script, we should now see the following output.
187+
188+
{% code title="java -jar SkriptLoader.jar" %}
189+
```log
190+
hello
191+
this was run from a function
192+
a function was run
193+
```
194+
{% endcode %}
195+
196+
To make our function more useful, we can give it some parameters. This will allow us to provide argument values when we run it.
197+
198+
```clike
199+
function my_function (name, number):
200+
trigger:
201+
print "this was run from a function"
202+
```
203+
204+
We can use these parameters like variables with `{name}` and `{number}` inside this function.
205+
206+
```clike
207+
function my_function (name, number):
208+
trigger:
209+
print "The name is " + {name}
210+
print "The number is " + {number}
211+
```
212+
213+
{% hint style="info" %}
214+
The `+` operator can be used to join text together.
215+
216+
Running `"hello " + "there"` will join these to make `"hello there"`.
217+
{% endhint %}
218+
219+
In order to use this function we will need to give it the `name` and `number` arguments when it's run. We can put these inside the `()` brackets in the run effect.
220+
221+
{% code title="myscript.bsk" %}
222+
```clike
223+
on load:
224+
trigger:
225+
run my_function("hello", 6)
226+
exit program
227+
228+
function my_function (name, number): // "hello", 6
229+
trigger:
230+
print "The name is " + {name} // hello
231+
print "The number is " + {number} // 6
232+
```
233+
{% endcode %}
234+
235+
We can also use variables as function arguments.
236+
237+
{% code title="myscript.bsk" %}
238+
```clike
239+
on load:
240+
trigger:
241+
set {a} to "Bob"
242+
set {b} to 4
243+
run my_function({a}, {b})
244+
exit program
245+
246+
function my_function (name, number):
247+
trigger:
248+
print "The name is " + {name} // Bob
249+
print "The number is " + {number} // 4
250+
```
251+
{% endcode %}
252+
253+
To learn more about using functions, see [here](../structures/members/functions.md).
254+
255+
To learn more about using variables, see [here](../structures/expressions/variables.md).
256+
257+
This site contains documentation for all syntax and language features, with explanations, examples and information about how they work.
258+
259+
By experimenting with the provided examples and following the simple grammar rules you should be able to learn the language quickly and use it.
260+
261+
### Running Your Scripts
262+
263+
To run your scripts, simply follow the same instructions as when [setting up ByteSkript](getting-started.md#setting-up-your-environment).
264+
265+
Scripts can be run with `java -jar path/to/SkriptLoader.jar` or by clicking your shell/bat file, if you created one.
266+
267+
This will tell **SkriptLoader** to load and run all scripts with the `.bsk` extension inside the `skript/` folder.
268+
269+
An `on load` event will be triggered for each one.
270+
271+
#### Using SkriptJarBuilder?
272+
273+
If you used **SkriptJarBuilder** instead of **SkriptLoader**, a new Jar file will have been created in the `compiled/` folder. It will be called `CompiledScripts.jar` by default, but you can change the name.
274+
275+
This Jar file can be run using `java -jar path/to/CompiledScripts.jar`.

structures/events.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Events
2+

0 commit comments

Comments
 (0)