Skip to content

Commit 0d9aae8

Browse files
committed
add hints to tutorials
1 parent b1c7aaa commit 0d9aae8

File tree

6 files changed

+93
-63
lines changed

6 files changed

+93
-63
lines changed

Diff for: src/assets/tutorials/commands.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ command /test:
148148
149149
```
150150

151-
{% hint style="danger" %}
151+
<div class="hint alert">
152+
<h3>Alert</h3>
152153
If two commands have the same name but different prefixes, only one will be registered.
153-
{% endhint %}
154+
</div>
154155

155156
### Aliases
156157

@@ -165,7 +166,8 @@ command /teleport <number> <number> <number>:
165166
teleport player to location(arg-1, arg-2, arg-3)
166167
```
167168

168-
{% hint style="danger" %}
169+
<div class="hint alert">
170+
<h3>Alert</h3>
169171
Aliases will not overwrite commands registered by other plugins. Say another plugin registers `/spawn`, and you have the following command:
170172

171173
```applescript
@@ -176,7 +178,7 @@ command /tp-to-spawn:
176178
```
177179

178180
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>
180182

181183
### Executable by
182184

@@ -223,9 +225,10 @@ There are also a number of expressions you can use to interact with the cooldown
223225

224226
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`.
225227

226-
{% hint style="info" %}
228+
<div class="hint info">
229+
<h3>Info</h3>
227230
You can see the full syntax for these expressions [here](https://docs.skriptlang.org/expressions.html#ExprCmdCooldownInfo).
228-
{% endhint %}
231+
</div>
229232

230233
```applescript
231234
# The same vote command but with an improved cooldown message.

Diff for: src/assets/tutorials/conditionals.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ Generic conditions are used when a dedicated condition does not exist or you hav
3535
if player's balance < 20
3636
```
3737

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+
<div class="hint info">
39+
<h3>Info</h3>
40+
<span>
41+
You can see all of the various generic condition syntaxes by clicking <a href="https://docs.skriptlang.org/docs#CondCompare">here, to view the comparison condition</a>.
42+
</span>
43+
</div>
4144

4245
## If Statements
4346

@@ -159,9 +162,10 @@ send "hello" if distance between player and {spawn} <= 10
159162

160163
Notice how there is no indentation differences, colons, and how the effect comes first and then the condition.
161164

162-
{% hint style="warning" %}
165+
<div class="hint info">
166+
<h3>Info</h3>
163167
Keep note that there is no `else if` or `else` options with this method.
164-
{% endhint %}
168+
</div>
165169

166170
## If Any and If All
167171

@@ -181,9 +185,10 @@ else:
181185
send "You didn't meet all the conditions! to player
182186
```
183187

184-
{% hint style="info" %}
188+
<div class="hint info">
189+
<h3>Info</h3>
185190
Notice the `else` statement! These multi-conditions can include `else if` and `else` statements inside of them!
186-
{% endhint %}
191+
</div>
187192

188193
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:
189194

Diff for: src/assets/tutorials/functions.md

+17-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Now, whenever someone joins, Skript sees `test()` and runs our function, broadca
2929

3030
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.
3131

32-
{% hint style="info" %}
32+
<div class="hint info">
33+
<h3>Info</h3>
3334
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?
3435

3536
```applescript
@@ -40,7 +41,7 @@ on join:
4041
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.&#x20;
4142

4243
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>
4445

4546
## Function Definitions
4647

@@ -91,11 +92,12 @@ function giveTenApples2(player: player, number-list: numbers):
9192
# imagine code here
9293
```
9394

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.&#x20;
95+
<div class="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.
9698

9799
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>
99101

100102
But we skipped over something earlier. We can give parameters **default values**, too.
101103

@@ -139,9 +141,10 @@ Secondly, notice how the function definition has changed. We now have this `retu
139141

140142
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.&#x20;
141143

142-
{% hint style="warning" %}
144+
<div class="hint warning">
145+
<h3>Warning</h3>
143146
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>
145148

146149
### Local Functions
147150

@@ -153,7 +156,8 @@ This is where **local** functions come into play. By putting `local` in front of
153156
[local] function functionName(...)...
154157
```
155158

156-
{% hint style="warning" %}
159+
<div class="hint warning">
160+
<h3>Warning</h3>
157161
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:
158162

159163
```applescript
@@ -179,7 +183,7 @@ on quit:
179183
When a player joins, the `join` event in `script-1.sk` runs. This calls the **local** function `test()`, which broadcasts `"local!"`.&#x20;
180184

181185
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>
183187

184188
## Full Definition
185189

@@ -282,6 +286,7 @@ To wrap up, functions are very useful tools to have in your belt. They're powerf
282286

283287
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.
284288

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+
<div class="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.
292+
</div>

Diff for: src/assets/tutorials/getting-started.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ date: 2/2/2024
55
url: https://github.com/SkriptLang/docs/blob/master/src/assets/tutorials/getting-started.md
66
---
77

8-
# Getting Started
8+
# Getting Started
9+
10+
We're happy to see you're interested in learning Skript.
11+
On the left, you'll find the list of all official tutorials currently available.
12+
13+
Have fun!

Diff for: src/assets/tutorials/loops.md

+33-37
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ loop all players:
4040
send "hey!" to loop-value
4141
```
4242

43-
{% hint style="info" %}
43+
<div class="hint info">
44+
<h3>Info</h3>
4445
If you're looping a specific expression, like `all players`, you can use `loop-type` as another version:
4546

4647
```
4748
loop all players:
4849
send "hey!" to loop-player
4950
```
50-
{% endhint %}
51+
</div>
5152

52-
#### Looping Over Lists
53+
**Looping Over Lists**
5354

5455
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.&#x20;
5556

@@ -74,7 +75,8 @@ Really, just one special feature, which is `loop-index`. This lets you access th
7475

7576
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.
7677

77-
{% hint style="danger" %}
78+
<div class="hint alert">
79+
<h3>Alert</h3>
7880
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.
7981

8082
```applescript
@@ -91,11 +93,12 @@ while true is true:
9193
send "hi"
9294
wait 1 tick
9395
```
94-
{% endhint %}
96+
</div>
9597

9698
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**.
9799

98-
{% hint style="warning" %}
100+
<div class="hint warning">
101+
<h3>Warning</h3>
99102
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.
100103

101104
```applescript
@@ -112,7 +115,7 @@ command abort-loop:
112115
trigger:
113116
set {abort-while-loop} to true
114117
```
115-
{% endhint %}
118+
</div>
116119

117120
### Do While
118121

@@ -174,7 +177,7 @@ loop integers between 1 and arg 1:
174177
broadcast loop-number * loop-number
175178
```
176179

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.
178181

179182
```applescript
180183
# searching for {_needle} in {_haystack::*}:
@@ -187,9 +190,10 @@ broadcast "Found needle at %{_index}%!"
187190

188191
## When to Use Loops
189192

190-
{% hint style="info" %}
193+
<div class="hint info">
194+
<h3>Info</h3>
191195
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>
193197

194198
Often, people will compare the performance of these two patterns:
195199

@@ -206,50 +210,42 @@ on join:
206210

207211
Before you keep reading, try to think about what the actual difference here is!
208212

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.
216214

217215
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.
218216

219217
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.**
220218

221219
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.
222220

223-
<figure><img src="../../.gitbook/assets/image (2).png" alt=""><figcaption></figcaption></figure>
224-
225-
{% hint style="info" %}
221+
<div class="hint info">
222+
<h3>Info</h3>
226223
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>
228225

229226
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.&#x20;
230227

231228
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.
232229

233-
{% hint style="info" %}
234-
TL/DR:
235-
236-
**every x, loop all players:**
230+
<div class="hint info">
231+
<h3>Summary</h3>
237232

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:**
242234

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.
244239

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:**
248241

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).
250245

251-
prefer using `every x, loop all players` when you are working with fast timings or smaller amounts of work.&#x20;
246+
**Conclusion:**
252247

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.)
250+
</div>
255251

Diff for: src/style.css

+16
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,20 @@ ul {
148148

149149
.-r-90 {
150150
@apply transform -rotate-90;
151+
}
152+
153+
.hint {
154+
@apply flex flex-col gap-4 p-4 rounded-md;
155+
}
156+
157+
.info {
158+
@apply bg-[#38b6e2] dark:bg-[#10799e];
159+
}
160+
161+
.warning {
162+
@apply bg-[#e4b03f] dark:bg-[#b98004];
163+
}
164+
165+
.alert {
166+
@apply bg-[#f96b6b] dark:bg-[#9e1010];
151167
}

0 commit comments

Comments
 (0)