By Alex K. After completing the first guide, you can’t do anything but
stare at the face, because we don’t have any scripts. Scripts are the instructions that the game uses to run. In this guide, we will learn some of the
basics regarding writing scripts in Godot. 1.
Close off your game (if it is still running in front of you). 2.
At the top left, right-click
on Icon in the Scene Tree, and press Attach Script…
3.
A
window titled Attach Node Script should pop up like below. 4.
Change the path to reflect what the code will be affecting. We’ll call it player. But make sure to leave the “res://” and the
“.gd” in place.
Like below:
5.
Hit Create. You are
automatically brought to the Script tab and the default script code is
showing. 6.
Before getting into the code, take a minute to switch between
the 2D Scene tab at the very top middle and the Script tab. 7.
Back
to the default script code, you should notice three things: · The extends Sprite2D means that this script can give orders to Sprite2D nodes. For
example, it could “change your image” or “play an animation”. · Everything indented
after _ready() will run a single
time when you start the game. This is
known at the _ready function. · Everything indented
after _process(delta: float) will run repeatedly
over and over. This is known as the
_process function.
8.
Let's start coding. Start by removing the pass from after _ready. 9.
Then add the following line (making sure it is indented): print("hello
world!!!!") 10.
Now run your game. Look
at the console (little box below the scripts). You should see the message
“Hello world” appear. Pretty cool
right? 11.
Optional: What do you
think happens if you were to place the print(“hello
world!!!!”) line under the _process function instead? Try it. |