Chapter 1: Hello World!
As some of you may know, the first thing that most people do when learning a programming language is create a Hello World program. That's exactly what we're going to do in Chapter 1 of this tutorial.
In This Chapter
We're going to create a command that broadcasts Hello World! to the server. It's extremely simple to do, and once you understand how it works, you can jump into much bigger projects.
Part 1: Creating Our Script
Before we start creating our script, we'll need a text editor to edit our scripts. There are a lot of text editors you can find online for editing your scripts. However, from the ones I've used, I think that these are some of the best editors for Skript: Sublime Text, Notepad++, Atom, skUnity Parser (ONLINE), Skript Editor (ONLINE). The last two are designed specifically for script. My personal favorite is VisualStudioCode (VSC for short), which can also be used for languages other than Skript.
Once you have your text editor installed, head over to the directory plugins\Skript\scripts\
in your server folder and create a new file with the name hello
and extension sk
. Our file should look like this, hello.sk
. For this tutorial, I am using atom to edit my scripts. (For atom, sublime, and notepad++ users) Right click the file, and click on Open With
. Now click on your text editor. If it does not appear, simply select Look for another app on this PC and browse to the location where you installed your text editor. Now double click on it, and you should be ready to go.
Part 2: Creating The Command
Let's start creating our command. To create a command in Skript, you simply type command
followed by your command (with or without a slash, it doesn't really matter.) This tells Skript that we're registering a new command, and what the command is called. Next, we're going to insert a :
(semicolon) at the end of the first line. Semicolons are used a lot in Skript to start a new code block. When we do this, Skript knows that everything we put inside the following code block is now part of our command. For the sake of this tutorial, I'm going to name our command hello
. Now we have 1 final thing to do before our command is created, we need to put a trigger:
inside it. This is another example of using semicolons in Skript. Every command as options such as permission:
and description:
etc. But 1 of them is not really an option. It's required. And that's the trigger:
which I just mentioned. The trigger option tells the command what it's supposed to do when someone runs it. We're going to write what happens in the trigger in the next part of this chapter. Our code should now look like this:
Part 3: Broadcasting A Message
Now, in Skript, there are 2 types of code. There are effects and there are expressions. Effects do not return anything, but expressions do. For example, kill the player
is an effect because it kills the player, but does not return any information to us. While name of player
is an expression because it tells us new information, the name of the player. You can find a list of effects and expressions here: Effects - Expressions
There are also functions, types and conditions but we are not learning about those for now.
We need to broadcast a message to the server. Let's think for a second, would this be an effect, or an expression? Since broadcasting a message wouldn't return any new information to us, this would be an effect rather than an expression. We can look through the list of skript expression to find the one we need, and luckily for us, there happens to be one! The effect is called broadcast, and the syntax for it is broadcast %texts% [(to|in) %worlds%].
That may seem complicated at first, but once you know how to read skript syntax, it will be a piece of cake. Let's look at the syntax, first thing we see is broadcast %texts%
. What is this mysterious %texts%? It's a placeholder, of course! This is where we will put what we want to broadcast, and the text inside the percent signs tell us what we need to put there. Since it's text
(Ignore the s for now), we know we have to input a, well... text! Next we see (to|in) %worlds%
surrounded by square brackets. The square brackets mean that this part of the syntax is completely optional. You may it use, you may not. We're going to skip this for now, since this tutorial will be way too long if I go over everything. Okay! Now we know how to use the syntax, so let's start writing some code. Like we learnt before, text
means we have to give a text input. In skript, text is surrounded by double quotes "
. So if we would want to broadcast Hello world
to the server, we will simply use broadcast "Hello world"
. And that's it! Your code should now look something like this.
Hello world
Conclusion
Congratulations! You just created your first ever script, and learnt about effects, expressions and commands in the process. You can now click on Chapter 2 to read about events.
Last updated