You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Aliases will not overwrite commands registered by other plugins. Say another plugin registers `/spawn`, and you have the following command:
170
172
171
173
```applescript
@@ -176,7 +178,7 @@ command /tp-to-spawn:
176
178
```
177
179
178
180
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.
179
-
{% endhint %}
181
+
</div>
180
182
181
183
### Executable by
182
184
@@ -223,9 +225,10 @@ There are also a number of expressions you can use to interact with the cooldown
223
225
224
226
If you've enabled `keep command last usage dates` in your `config.sk` file, you can get the last time the player used the command with `last usage date`.
225
227
226
-
{% hint style="info" %}
228
+
<divclass="hint info">
229
+
<h3>Info</h3>
227
230
You can see the full syntax for these expressions [here](https://docs.skriptlang.org/expressions.html#ExprCmdCooldownInfo).
228
-
{% endhint %}
231
+
</div>
229
232
230
233
```applescript
231
234
# The same vote command but with an improved cooldown message.
Copy file name to clipboardExpand all lines: src/assets/tutorials/conditionals.md
+12-7
Original file line number
Diff line number
Diff line change
@@ -35,9 +35,12 @@ Generic conditions are used when a dedicated condition does not exist or you hav
35
35
if player's balance < 20
36
36
```
37
37
38
-
{% hint style="info" %}
39
-
You can see all of the various generic condition syntaxes [here, under the Comparison condition](https://docs.skriptlang.org/conditions.html#CondCompare).
40
-
{% endhint %}
38
+
<divclass="hint info">
39
+
<h3>Info</h3>
40
+
<span>
41
+
You can see all of the various generic condition syntaxes by clicking <ahref="https://docs.skriptlang.org/docs#CondCompare">here, to view the comparison condition</a>.
42
+
</span>
43
+
</div>
41
44
42
45
## If Statements
43
46
@@ -159,9 +162,10 @@ send "hello" if distance between player and {spawn} <= 10
159
162
160
163
Notice how there is no indentation differences, colons, and how the effect comes first and then the condition.
161
164
162
-
{% hint style="warning" %}
165
+
<divclass="hint info">
166
+
<h3>Info</h3>
163
167
Keep note that there is no `else if` or `else` options with this method.
164
-
{% endhint %}
168
+
</div>
165
169
166
170
## If Any and If All
167
171
@@ -181,9 +185,10 @@ else:
181
185
send "You didn't meet all the conditions! to player
182
186
```
183
187
184
-
{% hint style="info" %}
188
+
<divclass="hint info">
189
+
<h3>Info</h3>
185
190
Notice the `else` statement! These multi-conditions can include `else if` and `else` statements inside of them!
186
-
{% endhint %}
191
+
</div>
187
192
188
193
This works well because we can check multiple conditions without losing code quality. But what if we only need a single condition to be met out of many? For example, what if we want **both** admins and builders to have build permission? In that case, we can use `if any` like this:
Copy file name to clipboardExpand all lines: src/assets/tutorials/functions.md
+17-12
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,8 @@ Now, whenever someone joins, Skript sees `test()` and runs our function, broadca
29
29
30
30
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.
31
31
32
-
{% hint style="info" %}
32
+
<divclass="hint info">
33
+
<h3>Info</h3>
33
34
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?
34
35
35
36
```applescript
@@ -40,7 +41,7 @@ on join:
40
41
And you'd be right. These two scripts behave exactly the same. In general, you can always just take the code from a function, plop it right into the place you're calling it from with some minor changes, and have it work the same. 
41
42
42
43
The main benefits come from when you're using the same code in multiple different locations. Functions allow you to only write that code once.
43
-
{% endhint %}
44
+
</div>
44
45
45
46
## Function Definitions
46
47
@@ -91,11 +92,12 @@ function giveTenApples2(player: player, number-list: numbers):
91
92
# imagine code here
92
93
```
93
94
94
-
{% hint style="warning" %}
95
-
Note that I used `()` around the number list. This is so that Skript doesn't get confused and think that `10, 20, 30` are all different parameters. 
95
+
<divclass="hint warning">
96
+
<h3>Warning</h3>
97
+
Note that I used `()` around the number list. This is so that Skript doesn't get confused and think that `10, 20, 30` are all different parameters.
96
98
97
99
If you're ever experiencing errors or weird bugs with your parameters, try making sure they're surrounded with `()`, it can solve a lot of issues.
98
-
{% endhint %}
100
+
</div>
99
101
100
102
But we skipped over something earlier. We can give parameters **default values**, too.
101
103
@@ -139,9 +141,10 @@ Secondly, notice how the function definition has changed. We now have this `retu
139
141
140
142
Finally, notice the new syntax at the end of the function: `return {_item}`. This is how we tell the function what value it should return. In this case, it's `{_item}`. Return will also stop execution of the function there, like `stop` does. 
141
143
142
-
{% hint style="warning" %}
144
+
<divclass="hint warning">
145
+
<h3>Warning</h3>
143
146
Note that you cannot use `wait` in a function that returns a value. It has to return it instantly, without delay.
144
-
{% endhint %}
147
+
</div>
145
148
146
149
### Local Functions
147
150
@@ -153,7 +156,8 @@ This is where **local** functions come into play. By putting `local` in front of
153
156
[local] function functionName(...)...
154
157
```
155
158
156
-
{% hint style="warning" %}
159
+
<divclass="hint warning">
160
+
<h3>Warning</h3>
157
161
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:
158
162
159
163
```applescript
@@ -179,7 +183,7 @@ on quit:
179
183
When a player joins, the `join` event in `script-1.sk` runs. This calls the **local** function `test()`, which broadcasts `"local!"`. 
180
184
181
185
When a player quits, 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!"`.
182
-
{% endhint %}
186
+
</div>
183
187
184
188
## Full Definition
185
189
@@ -282,6 +286,7 @@ To wrap up, functions are very useful tools to have in your belt. They're powerf
282
286
283
287
I hope now you've got a grasp on how functions work, at least enough to go and experiment on your own. All the tutorials in the world can't teach you what good old trial and error can.
284
288
285
-
{% hint style="danger" %}
286
-
If you didn't like anything about this tutorial, or found it hard to understand, message me on Discord at Sovde#0001, or tag me in the SkUnity discord.
287
-
{% endhint %}
289
+
<divclass="hint alert">
290
+
<h3>Alert</h3>
291
+
If you didn't like anything about this tutorial, or found it hard to understand, message me on Discord at @sovdeeth, or tag me in the SkUnity discord.
Copy file name to clipboardExpand all lines: src/assets/tutorials/loops.md
+33-37
Original file line number
Diff line number
Diff line change
@@ -40,16 +40,17 @@ loop all players:
40
40
send "hey!" to loop-value
41
41
```
42
42
43
-
{% hint style="info" %}
43
+
<divclass="hint info">
44
+
<h3>Info</h3>
44
45
If you're looping a specific expression, like `all players`, you can use `loop-type` as another version:
45
46
46
47
```
47
48
loop all players:
48
49
send "hey!" to loop-player
49
50
```
50
-
{% endhint %}
51
+
</div>
51
52
52
-
#### Looping Over Lists
53
+
**Looping Over Lists**
53
54
54
55
Loops go hand in hand with lists, as every loop needs a list of something to loop over. The `%number% times` expression actually creates a list of numbers, so `set {_x::*} to 3 times` is equivalent to `set {_x::*} to 1, 2, and 3`. Use this knowledge wisely. 
55
56
@@ -74,7 +75,8 @@ Really, just one special feature, which is `loop-index`. This lets you access th
74
75
75
76
While loops are the for loop's more temperamental cousin. They keep looping as long as a condition is true, which makes them great for repeating things over time, doing a specific action a dynamic number of times, or crashing your server.
76
77
77
-
{% hint style="danger" %}
78
+
<divclass="hint alert">
79
+
<h3>Alert</h3>
78
80
Since while loops will not stop until the condition fails, they can run infinitely, potentially crashing your server. Make sure your while loop **will always exit****or add a wait to it.** Adding a wait stops the while loop until the delay is done, allowing your server to actually run.
79
81
80
82
```applescript
@@ -91,11 +93,12 @@ while true is true:
91
93
send "hi"
92
94
wait 1 tick
93
95
```
94
-
{% endhint %}
96
+
</div>
95
97
96
98
While loops are most often used to do periodic work while a condition is true, say, to do something every 5 ticks while a player is online. However, you do need to be careful that you can stop a while loop at will, since **reloading a script will not stop a running while loop**.
97
99
98
-
{% hint style="warning" %}
100
+
<divclass="hint warning">
101
+
<h3>Warning</h3>
99
102
While loops will not stop when you reload the script that they are in. They will doggedly run until their condition is no longer true. This is a good reason to either use a periodical event (when appropriate) or to add a special case to abort a loop.
100
103
101
104
```applescript
@@ -112,7 +115,7 @@ command abort-loop:
112
115
trigger:
113
116
set {abort-while-loop} to true
114
117
```
115
-
{% endhint %}
118
+
</div>
116
119
117
120
### Do While
118
121
@@ -174,7 +177,7 @@ loop integers between 1 and arg 1:
174
177
broadcast loop-number * loop-number
175
178
```
176
179
177
-
`exit loop` is for, well, exiting loops. This is useful for preventing runaway while loops, as we've seen earlier, or just exiting once you find what you need.
180
+
`exit loop` is for exiting loops. This is useful for preventing runaway while loops, as we've seen earlier, or just exiting once you find what you need.
178
181
179
182
```applescript
180
183
# searching for {_needle} in {_haystack::*}:
@@ -187,9 +190,10 @@ broadcast "Found needle at %{_index}%!"
187
190
188
191
## When to Use Loops
189
192
190
-
{% hint style="info" %}
193
+
<divclass="hint info">
194
+
<h3>Info</h3>
191
195
This is a more of the in-the-weeds performance comparison, so if you're just here to learn about loops, you can skip this.
192
-
{% endhint %}
196
+
</div>
193
197
194
198
Often, people will compare the performance of these two patterns:
195
199
@@ -206,50 +210,42 @@ on join:
206
210
207
211
Before you keep reading, try to think about what the actual difference here is!
208
212
209
-
I'll wait.
210
-
211
-
Don't worry, I'll still be here.
212
-
213
-
Alright.
214
-
215
-
So, behind the scenes, there's a thing called a Scheduler. This is in charge of scheduling when things run on your server. When we make an `every x` periodical event, Skript tells the scheduler to run this thing every x time. This is pretty simple and straightforward, which means it's very easy for Skript to come back later and tell the scheduler to stop running it. The scheduler just gives Skript a number to call if it wants the task ended.
213
+
Behind the scenes, there's a thing called a Scheduler. This is in charge of scheduling when things run on your server. When we make an `every x` periodical event, Skript tells the scheduler to run this thing every x time. This is pretty simple and straightforward, which means it's very easy for Skript to come back later and tell the scheduler to stop running it. The scheduler just gives Skript a number to call if it wants the task ended.
216
214
217
215
The downside here is that it runs the `do something` for every player, all at once. If you have a lot of players, or a lot of work to do per player, this can sometimes result in small lag spikes every time the code runs.
218
216
219
217
While loops, meanwhile, are a bit more complicated. Skript has to run the code within the loop to determine what the next behavior is, so when it hits the `wait 10 ticks`, it tells the scheduler "hey, can you restart this code in 10 ticks?" and the scheduler does just that. The downside, though, is that Skript doesn't really have control over the code anymore. Since every single iteration of the loop creates a new scheduled task, Skript doesn't know what number to call to stop the loop. This means that the while loop itself is the only thing that can stop it, which it does by failing the condition and not running the code inside itself, therefore not running the `wait`. **All this to say, `/sk reload` will not stop while loops.**
220
218
221
219
However, it also comes with some benefits. Since players don't usually all join at the exact same time, the while loops running for each individual player are going to trigger at slightly different times. This helps solve our problem with `every x`, where we were getting lag spikes.
Note that we didn't change the amount of work that we were doing, we just spread that work out over multiple ticks.
227
-
{% endhint %}
224
+
</div>
228
225
229
226
This means the `on join, while online` pattern is good for spreading work out, but comes with the downsides of a) not stopping with a reload, and b) potentially starting multiple loops for one player if you're not careful. 
230
227
231
228
It also means that for short waits, like 1 to 5 ticks, the benefits of spreading work out will be very small, and a periodical event will be your better bet. While loops also can't address sustained lag, only lag spikes.
232
229
233
-
{% hint style="info" %}
234
-
TL/DR:
235
-
236
-
**every x, loop all players:**
230
+
<divclass="hint info">
231
+
<h3>Summary</h3>
237
232
238
-
* simple to set up
239
-
* safe
240
-
* reload-friendly
241
-
* can cause lag spikes if the work done is too much to do in one tick
233
+
**Every x, loop all players:**
242
234
243
-
**on join, while online:**
235
+
* Simple to set up,
236
+
* Safe,
237
+
* Reload-friendly,
238
+
* Can cause lag spikes if the work done is too much to do in one tick.
244
239
245
-
* can spread work over multiple ticks if the delay is long enough ( >5 ticks)
246
-
* not reload-friendly
247
-
* needs extra work to make safe (prevent multiple loops from running at once for one player)
240
+
**On join, while online:**
248
241
249
-
**conclusion:**
242
+
* Can spread work over multiple ticks if the delay is long enough ( >5 ticks),
243
+
* Not reload-friendly,
244
+
* Needs extra work to make safe (prevent multiple loops from running at once for one player).
250
245
251
-
prefer using `every x, loop all players` when you are working with fast timings or smaller amounts of work. 
246
+
**Conclusion:**
252
247
253
-
prefer `on join, while online` when you are working with slower timings or larger amounts of work (updating scoreboards is a good example, you only need to do this at most once a second.)
254
-
{% endhint %}
248
+
* Prefer using `every x, loop all players` when you are working with fast timings or smaller amounts of work.
249
+
* Prefer `on join, while online` when you are working with slower timings or larger amounts of work (updating scoreboards is a good example, you only need to do this at most once a second.)
0 commit comments