A quick introduction to scripts

Knowledgebase / A quick introduction to scripts

 

hello-world

Let’s start with a classic: Hello world! Every programmer starts off creating this basic program that displays text on screen.

We want the message “Hello, world!” to appear when the game starts. We’ll need to create the script for this, then attach that script to a game object.

First, place a game object on the stage, then right-click on it and choose “Add script”.

hello-world-2

To start with, we need an event block to trigger actions. The event block we want needs to activate when the level stars. The right block for the job is “When the level starts”. Find this block under the Events tab, and drag it into the working area.

hello-world-3

To display text we need a block called “Create new textfield with text”, and you can find this block under the Draw tab. Drag it inside the “When level starts” block so that the two blocks snap together.

hello-world-4

Now type into the emtpy slot “Hello, world!” to complete our script.

hello-world-5

Click Save, give your script a name, then close the script editor. Then click PLAY to test it out.

hello-world-6

Congratulations! You’ve programmed your first script. Have a play around with more blocks and see what you can create.