Skip to content

Commit 5c26410

Browse files
sovdeethgitbook-bot
authored andcommitted
GITBOOK-55: 2.7 updates
1 parent 3d79339 commit 5c26410

22 files changed

+117
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This gitbook contains a crash course in Skript programming, so if you're here to
77
For those of you who are already familiar with Skript, go ahead and use the navigation table on the left to jump to what you're interested in. Currently, only a few pages are actually complete, so you can use the links below to jump to completed tutorials. If you're interested in helping out, the github repo is linked on the right. Pull requests are welcome!
88

99
{% hint style="warning" %}
10-
**Note:** These tutorials are for the current version of the SkriptLang Skript fork (2.6.4) and are not guaranteed to be correct for other versions or forks. This site does not include any tutorials for addons, either.
10+
**Note:** These tutorials are for the current version of the SkriptLang Skript fork (2.7.0) and are not guaranteed to be correct for other versions or forks. This site does not include any tutorials for addons, either.
1111
{% endhint %}
1212

1313
### Completed Pages

SUMMARY.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727

2828
## Unfinished
2929

30-
* [Syntax Types](unfinished/syntax-types/README.md)
31-
* [Reading Syntax](unfinished/syntax-types/reading-syntax.md)
32-
* [Events](unfinished/syntax-types/events.md)
33-
* [Conditions](unfinished/syntax-types/conditions.md)
34-
* [Effects](unfinished/syntax-types/effects.md)
35-
* [Literals and Aliases](unfinished/syntax-types/literals-and-aliases.md)
36-
* [Expressions](unfinished/syntax-types/expressions.md)
37-
* [Sections](unfinished/syntax-types/sections.md)
38-
* [Auxiliary Guides](unfinished/auxiliary-guides/README.md)
30+
* [Syntax Types](syntax-types/README.md)
31+
* [Reading Syntax](syntax-types/reading-syntax.md)
32+
* [Events](syntax-types/events.md)
33+
* [Conditions](syntax-types/conditions.md)
34+
* [Effects](syntax-types/effects.md)
35+
* [Literals and Aliases](syntax-types/literals-and-aliases.md)
36+
* [Expressions](syntax-types/expressions.md)
37+
* [Sections](syntax-types/sections.md)
38+
* [Auxiliary Guides](auxiliary-guides/README.md)
3939
* [Cooldowns](unfinished/auxiliary-guides/cooldowns.md)
40-
* [Using Math](unfinished/auxiliary-guides/using-math.md)
41-
* [Useful Config Options](unfinished/auxiliary-guides/useful-config-options.md)
42-
* [Naming Conventions](unfinished/auxiliary-guides/naming-conventions.md)
43-
* [Writing Good Code](unfinished/auxiliary-guides/writing-good-code.md)
40+
* [Using Math](auxiliary-guides/using-math.md)
41+
* [Useful Config Options](auxiliary-guides/useful-config-options.md)
42+
* [Naming Conventions](auxiliary-guides/naming-conventions.md)
43+
* [Writing Good Code](auxiliary-guides/writing-good-code.md)
File renamed without changes.

core-concepts/commands.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Here's the full list of features that you can use in your commands. They're all
2121

2222
```applescript
2323
command /<command name> <arguments>:
24+
prefix: # command prefix, defaults to "skript"
2425
aliases: # alternate command names
2526
executable by: # players or console
2627
usage: # the message that explains how to use the command
@@ -122,17 +123,28 @@ command /give-item <item> [with name <text>] [[and] with lore <text>]:
122123
give player {_item}
123124
```
124125

125-
### Executable by
126+
### Prefix
126127

127-
Who can execute this command. The options are `players`, `console`, or `players and console`.
128+
A prefix is something **all** commands have, and it goes before the command when Minecraft registers them. You do not have to type this out when executing commands, but you can. The prefix, by default, is `skript`, which means if you leave this blank your command (with its prefix) will look like `/skript:commandName`.
128129

129130
```applescript
130-
command /shutdown:
131-
executable by: console
132-
trigger:
133-
shutdown the server
131+
# This command can be run by "/test" or "/testing_prefix:test"
132+
command /test:
133+
prefix: testing_prefix
134+
trigger:
135+
broadcast "test"
136+
137+
# This command can be run by "/test" or "/skript:test"
138+
command /test:
139+
trigger:
140+
broadcast "test"
141+
134142
```
135143

144+
{% hint style="danger" %}
145+
If two commands have the same name but different prefixes, only one will be registered.
146+
{% endhint %}
147+
136148
### Aliases
137149

138150
Aliases are alternate names for your command. For example, the command `/teleport` could have an alias `/tp`. Like in the command name, the forward slash (`/`) is optional.
@@ -146,6 +158,30 @@ command /teleport <number> <number> <number>:
146158
teleport player to location(arg-1, arg-2, arg-3)
147159
```
148160

161+
{% hint style="danger" %}
162+
Aliases will not overwrite commands registered by other plugins. Say another plugin registers `/spawn`, and you have the following command:
163+
164+
```applescript
165+
command /tp-to-spawn:
166+
aliases: spawn, sp
167+
trigger:
168+
teleport player to spawn of world
169+
```
170+
171+
If you run `/spawn`, that other plugin's command will run. You'll need to register a new command with that name and have it run your first command.
172+
{% endhint %}
173+
174+
### Executable by
175+
176+
Who can execute this command. The options are `players`, `console`, or `players and console`.
177+
178+
```applescript
179+
command /shutdown:
180+
executable by: console
181+
trigger:
182+
shutdown the server
183+
```
184+
149185
### Description
150186

151187
The description of the command. Other plugins can get/show this with `/help`, like `/help teleport`.

core-concepts/indentation/conditionals.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ Notice how there is no indentation differences, colons, and how the effect comes
156156
Keep note that there is no `else if` or `else` options with this method.
157157
{% endhint %}
158158

159+
## If Any and If All
160+
161+
new 2.7 shit
162+
159163
## Ternary Operators
160164

161165
Ternaries are similar to the `do if` effect, but they're expressions instead. They're designed to return one thing if a condition passes and a different thing if it does not pass. A simple but straight forward example looks something like:

core-concepts/indentation/functions.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ on join:
2020

2121
Now, whenever someone joins, Skript sees `test()` and runs our function, broadcasting "hello world!". The act of telling Skript to run a function is named a **function call**. We just called the function test, or ran it, by using its function call.
2222

23+
Function can be called from anywhere, and at (nearly) any time. You can use them across files! The only restriction is using them in `on load` events. Be careful there. You can also restrict a function to work only in 1 file by using `local`, which we'll get to later.
24+
2325
{% hint style="info" %}
2426
This might seem a little, well, useless. Why come up with this whole function thing when you can just write the code when you want it? Why couldn't we just write the following?
2527

@@ -43,7 +45,7 @@ function functionName():
4345

4446
This is a basic function, like we saw before. The only thing that changes here is the `fuctionName`. The first character must be an alphabetic character, eg a letter, but the following characters can include digits and underscores as well. Common practices are to name functions in `camelCase` or `snake_case`.
4547

46-
However, this is rather limiting. What if we want to do something to an object? Say we have a function called `giveTenApples()`. We don't know who to give to inside the function! This is where **parameters** come into player.
48+
However, this is rather limiting. What if we want to do something to an object? Say we have a function called `giveTenApples()`. We don't know who to give the apples to! This is where **parameters** come into play.
4749

4850
### Parameters
4951

@@ -134,16 +136,55 @@ Finally, notice the new syntax at the end of the function: `return {_item}`. Thi
134136
Note that you cannot use `wait` in a function that returns a value. It has to return it instantly, without delay.
135137
{% endhint %}
136138

137-
### Full Definition
139+
### Local Functions
140+
141+
The final piece of the puzzle is whether the function is **local or global**. By default, functions are always global. This means you put the function definition in one script file, and you can call the function from any other script! It'll always do the same thing. Sometimes, however, you'll want your function to only be used by 1 script file. Perhaps you want to avoid naming conflicts, where you might accidentally have two functions named `subtract()`.&#x20;
142+
143+
This is where **local** functions come into play. By putting `local` in front of your function definition, you can make it so that only _this_ script file can use that function. Any other script file won't even know that it exists. &#x20;
144+
145+
```applescript
146+
[local] function functionName(...)...
147+
```
148+
149+
{% hint style="warning" %}
150+
If there's a global function of the same name, your local function will **always** be prioritized over the global version. If that's a bit confusing, here's an example:
151+
152+
```applescript
153+
# ----------------
154+
# in script-1.sk
155+
local function test():
156+
broadcast "local!"
157+
158+
on join:
159+
test()
160+
# ----------------
161+
162+
# ----------------
163+
# in script-2.sk
164+
function test():
165+
broadcast "global!"
166+
167+
on quit:
168+
test()
169+
# ----------------
170+
```
171+
172+
When a player joins, the `join` event in `script-1.sk` runs. This calls the **local** function `test()`, which broadcasts `"local!"`.&#x20;
173+
174+
When a player joins, the `quit` event in `script-2.sk` runs. This can't see the local version of `test()`, so it calls the **global** `test()`, which broadcasts `"global!"`.
175+
{% endhint %}
176+
177+
## Full Definition
138178

139179
Now that we've explained all the parts, let's show the whole function at once:
140180

141181
```applescript
142-
function functionName(parameterName: parameterType = defaultValue) :: returnType:
182+
[local] function functionName(parameterName: parameterType = defaultValue) :: returnType:
143183
```
144184

145185
Hopefully by now you know all these parts, but let's recap:
146186

187+
* **\[local]**: Whether this function is local or global. (global is default)
147188
* **functionName:** the name of the function, starts with a letter and can use letters, numbers, and underscores
148189
* **parameterName:** Optional. The name of the parameter, follows the same rules as variable names. Will be accessible as a local variable of the same name in the function.
149190
* **parameterType:** Required if you have a parameter. Tells Skript what type the parameter will be. Use `object` if you're unsure.

core-concepts/variables/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Perfect, right? We save the player's location to a variable, and then when they
6262

6363
Well, this is only partially correct. You see, since global variables are, in fact, global, there's only one of them at any time. So if someone else comes along and does `/sethome`, the `{home}` variable now has their home location, and if you use `/home`, you're getting teleported to their home instead!
6464

65-
To solve this, we need to make the variable unique for each player. The best method to do this is to use the player's uuid as part of the variable name. If you use just `player` or `player's name`, you run the risk of the data no longer being useful when the player changes their name. This is why it's always recommended to use uuids, or enable the config option `use player UUIDs in variable names`, which is explained [here](../../unfinished/auxiliary-guides/useful-config-options.md).
65+
To solve this, we need to make the variable unique for each player. The best method to do this is to use the player's uuid as part of the variable name. If you use just `player` or `player's name`, you run the risk of the data no longer being useful when the player changes their name. This is why it's always recommended to use uuids, or enable the config option `use player UUIDs in variable names`, which is explained [here](../../auxiliary-guides/useful-config-options.md).
6666

6767
```applescript
6868
command /sethome:

introduction/installation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ Installing Skript is no different from any other plugin. You download the latest
66
You should ensure your server meets the requirements for running Skript:
77

88
* A Spigot, Paper, or Paper fork server jar. Spigot is the absolute minimum and Skript includes some features that are only accessible when using Paper or a fork of Paper.
9-
* Minecraft Version. Currently, 2.6.4 works for 1.9 - 1.19.3, but 2.7 will only work for 1.13+.&#x20;
9+
* Minecraft Version. Skript 2.7 works for versions 1.13+.&#x20;
1010
* 1.8 support can be found [here](https://github.com/Matocolotoe/Skript-1.8/releases), but is not official, nor recommended, nor guaranteed to work.
11+
* 1.9-1.12 support is limited to old versions of Skript that do not receive updates (2.6.4)&#x20;
1112
{% endhint %}
1213

1314
After you've downloaded the jar file, put it in your `plugins` folder in your server directory. Restart the server and Skript should generate the folder `plugins/Skript`.&#x20;

introduction/the-basics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ We want a code that fills the player's hunger bar, but we don't know what to wri
3939
This may seem annoying, or frivolous, but please actually visit the docs. They're your best tool for finding what you need when you have questions.
4040
{% endhint %}
4141

42-
You should see one result, called Food Level. If you look at the patterns, you can see that `player`, `food`, and `level` all show up in there. It might be a bit hard to read, which is why we have a [syntax reading tutorial](../unfinished/syntax-types/reading-syntax.md), but it's pretty simple once you know how. For now, we'll just look at the example.
42+
You should see one result, called Food Level. If you look at the patterns, you can see that `player`, `food`, and `level` all show up in there. It might be a bit hard to read, which is why we have a [syntax reading tutorial](../syntax-types/reading-syntax.md), but it's pretty simple once you know how. For now, we'll just look at the example.
4343

4444
```applescript
4545
set the player's food level to 10
@@ -202,7 +202,7 @@ set {_tool-text} to "%player's tool%"
202202

203203
### Using Events
204204

205-
We've been using a command all this time, but events are another extremely useful way to trigger code in Skript. Events are things that happen when certain, well, events happen in the game. Say the player jumps. There's an event for that. Say a furnace burns a piece of coal. There's an event for that. Say a sheep regrows its wool. There's an event for that. You can see all the events at [https://docs.skriptlang.org/events.html](https://docs.skriptlang.org/events.html). You can also learn more about them in the[ Events page](../unfinished/syntax-types/events.md).
205+
We've been using a command all this time, but events are another extremely useful way to trigger code in Skript. Events are things that happen when certain, well, events happen in the game. Say the player jumps. There's an event for that. Say a furnace burns a piece of coal. There's an event for that. Say a sheep regrows its wool. There's an event for that. You can see all the events at [https://docs.skriptlang.org/events.html](https://docs.skriptlang.org/events.html). You can also learn more about them in the[ Events page](../syntax-types/events.md).
206206

207207
Events are kind of like commands in that they're never indented. Commands and events always start all the way to the left. Since we've been giving players food, let's use an `on consume` event:
208208

readme/syntax-overview.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Syntax is a word that means the set or rules or conventions that define a langua
55
{% hint style="info" %}
66
Skript has a few main types of syntaxes:
77

8-
* Top-level syntaxes like events, commands, function definitions, and the option and variables sections.
8+
* Structures like events, commands, function definitions, and the option and variables sections.
99
* Sections and conditions, syntaxes that require some indentation.
1010
* Effects, expressions, literals and similar syntaxes that make up the fundamental bits of a line of Skript code.
1111
{% endhint %}
@@ -14,7 +14,7 @@ I will warn you, this is a very long page. Feel free to use the right-side bar t
1414

1515
## Crash Course in Reading Syntax
1616

17-
You may have looked at the Skript docs and been very confused on how to turn that long string of words and symbols into actual code. The docs can be a bit daunting if you don't know the rules for how to read them. Here's a little crash course, but if you want more detail, head over to [Reading Syntax](../unfinished/syntax-types/reading-syntax.md).
17+
You may have looked at the Skript docs and been very confused on how to turn that long string of words and symbols into actual code. The docs can be a bit daunting if you don't know the rules for how to read them. Here's a little crash course, but if you want more detail, head over to [Reading Syntax](../syntax-types/reading-syntax.md).
1818

1919
```applescript
2020
(message|send [message[s]]) %objects% [to %players/console%] [from %player%]
@@ -35,9 +35,9 @@ message {_something} to player from {_another player}
3535

3636
Hopefully this helps you see how the syntax in the docs can be turned into actual Skript code.
3737

38-
## Top-Level Syntaxes
38+
## Structures
3939

40-
Top level syntaxes are things you would write to start out a script:
40+
Structures, or top-level syntaxes, are things you would write to start out a script:
4141

4242
```applescript
4343
# an event
@@ -53,11 +53,11 @@ function name(p: player) :: text:
5353
# run code
5454
```
5555

56-
You don't need to know exactly how to use all of these, they'll be explained in greater detail later. **The important part is that none of them are indented.** All top-level syntaxes are just that, top-level. They're never indented. They contain every other bit of code inside of them. If you ever get the error `"All code must be put inside an event"`, you've encountered this principle.
56+
You don't need to know exactly how to use all of these, they'll be explained in greater detail later. **The important part is that none of them are indented.** All structures are top-level, they stay to the left. They're never indented. They contain every other bit of code inside of them. If you ever get the error `"All code must be put inside an event"`, you've encountered this principle.
5757

5858
## Fundamental Syntaxes
5959

60-
Top-level syntaxes are pretty straightforward, just write an event, or a command, or whatever. Everything else is a little more complicated, but we'll break it down to the simple bits. The basic structure of a line of Skript code consists of two main elements: Effects and Expressions.
60+
Structures are pretty straightforward, just write an event, or a command, or whatever. Everything else is a little more complicated, but we'll break it down to the simple bits. The basic structure of a line of Skript code consists of two main elements: Effects and Expressions.
6161

6262
### Effects
6363

@@ -105,7 +105,7 @@ command /give-food <player>:
105105
give 5 steak to arg-1
106106
```
107107

108-
This is a pretty short line, so there isn't too much to dissect. Firstly, we have our top-level syntax, which is a command. We won't be going in to the details of those here. Inside that command, we have this line of code: `give 5 steak to arg-1`. This consists of 1 effect, an alias, and a simple expression.
108+
This is a pretty short line, so there isn't too much to dissect. Firstly, we have our structure, which is a command. We won't be going in to the details of those here. Inside that command, we have this line of code: `give 5 steak to arg-1`. This consists of 1 effect, an alias, and a simple expression.
109109

110110
The effect, as always, begins our line. Here we're using the Change effect, a very common effect. Specifically, we're using the `give` syntax of the effect:
111111

@@ -127,7 +127,7 @@ on right click:
127127
send "%player's name% and %type of player's tool%" to all players
128128
```
129129

130-
Again, we have a top-level element, this time a right-click event. Inside this event, we have a `send` effect.
130+
Again, we have a structure, this time a right-click event. Inside this event, we have a `send` effect.
131131

132132
```applescript
133133
(message|send [message[s]]) %objects% [to %players/console%] [from %player%]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)