I’m new to Godot and I don’t know anything about gdscript, although I’d like to learn. What can I do to learn?I’m new to Godot and I don’t know anything about gdscript, although I’d like to learn. What can I do to learn to program in gdscript?
Tutorials are great, and you can find them all over Youtube and the internet. But when you start building things on your own, I highly recommend taking a minute and just thinking through what you want each script to accomplish, each function to accomplish.
For example, if you have an interactable object (let’s say a door), just take a minute and look at it from the end user point of view.
When the player approaches the door, the door needs to know when they’re close enough to interact. That’s going to require an Area (3D or 2D) and collision. The player is also going to need to know that they are close enough to interact. That’s going to be some kind of Sprite or Label or other cue. The player is going to need to press a button to interact, so we’re dealing with an input script. And we have to make sure that that input only fires if they’re within interactivity range, so we’ll probably need a boolean on the Area. Once all of that is accomplished, we’ll need some kind of animation to actually open the door. Optionally, the door may automatically close once the player moves out of the Area.
Write all of this out as comments first.
extends Node3D
# the door is closed to start, this would be the _ready() function
# the player gets close enough to interact, an Area that detects the player
# a prompt pops up, showing they can interact, a Sprite, Label, etc.
# they press a button and the door opens, use _input() or _unhandled_input()
# they leave the area and the door closes (the prompt also disappears)
No matter what coding language you’re using, just writing things out as simple steps will help to focus what you actually need for this script.
And if you find yourself writing out a whole bunch of “if” statements that cross-reference too many other nodes or conditions, reconsider what you’re trying to do and if it wouldn’t be better to split the script into something like a state machine (a topic for another day).