How to Learn and Use GdScript

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By linuxtopia
:warning: Old Version Published before Godot 3 was released.

Hello guys,

My question on GdScript that title has sum of it. I can not learn it and not use it how I want. I just look at demos, tutorials, examples, demos but can not use myself for my needs.

Ahghh… I know you will Ctrl+C and Ctrl+V the docs of GdScript here as a link. However the big trouble is already that docs. My brain really confused to script my game with Class Reference and Gdscript together when read docs. Especially for Reference and it’s elements make my mind blurred.

Okay Let me explain my stuck more clearly.

  • If I used a Node2D, Node or Are2D etc. node and then write any script
    for it. Should my script’s all element, inheritance come from that used node type?

I ask it because can not decide which of method, func or other element is for my need and where come from. Not only for that condition and that syntax but generally. Look below!

Godot

if not appear >> Imgur: The magic of the Internet

  • And other trouble side of me on docs is explanation, what makes me confused. Whenever I search any class element just see some little expressions side by side!.. And don’t know what these terms corresponds to what. So can not write accurately script for my game project. Look at the below image again please.

Godot Reference descriptive
if not appear >> Imgur: The magic of the Internet

Someone help me how to read and use that docs to script. I click an element and that grab me to another link place and there makes me more confused, like endless curve :confused:

As a proposal from me to developers. Please you may make these docs more readable and comprehensible.

Note:

Sorry for my English :smiley:

Godot terms

if not appear >> Imgur: The magic of the Internet

:bust_in_silhouette: Reply From: Zylann

First of all, if you are completely new to programming in general, I can understand that some aspects of scripting in Godot can be confusing. The documentation is not a programming tutorial, it implicitely requires some basic notions like variables, functions, a bit of inheritance and math.

Your question as been asked already, you can find some links here by doing a quick search: https://forum.godotengine.org/7981/any-good-tutorials?show=7981#q7981
more here: https://forum.godotengine.org/4335/where-find-godot-engine-tutorials-lets-collect-links-together?show=4335#q4335

If you need to chat with devs, you can ask on IRC: Kiwi IRC
or on this Godot Discord server: Godot Engine

About the images you posted:

  • When you see something.instance(), it almost always means that something is a PackedScene. In fact, you will not find any other function having that name. You can see the word “instance” mixed in a lot of other places because “instance” is a programming concept, meaning that you create an object according to a model. In Godot, a PackedScene contains information to build a scene. Using instance() will create that scene, as many times as you want.

  • The second screenshot is an example of missing documentation, I agree it’s frustrating :s
    Contributors are slowly improving it, it’s a huge game engine and it takes time to write all these help files (and even more to translate it in many languages).

  • In the third screenshot… well again, these are programming basics, however some of it is specific to the documentation:

  • void: means the function returns vo value. For example, writing var result = the_function() will not put anything into result.

  • const: this means the function will not modify the object it is used on. For example, on a Node2D, the function will not change anything in the node, just give you some information.

  • float: in computers, this is how we commonly call a number that can have decimals (like 3.14 or 0.5). In the screenshot, it means the function returns that kind of number.

  • Vector2: this is a math vector with an X and Y component. Unlike single numbers, you can use it to represent a position in two dimensions, or a direction. You can click on it and see its description.

  • pivot: this is a parameter, the name usually depends on the function (it could be any name, as long as it’s relevant). The choice of “pivot” usually means it’s the center of something. In your case, that would be “where is the center of the node”.

A small addition to the answer:
If you are zero on programming, start with some python basics, that will help you to understand some of the tools.

If you are too young or your algebra is not your strong part, read a bit and be prepared to learn vector math while you do your games or prototypes.

When in Godot, go slowly with things, work on a basic game like a fixed shooter, one element at time, and start on paper, not on screen.

Game developing, as any programing related stuff, requires patience and to study (a lot sometimes).

eons | 2016-11-09 00:27

Umm… Thanks for your answers and giving time to my question.

Sorry not to mention about my programming experince. Yeah I have coding knowlodge for years especially on Pyhton and Lua. However have no any C++ but some C# and Java. I think some part of or most part of Reference manual is based on C++

I had searched community of Godot from reddit to Facebook plus here but have never seen any related question with my statement. Then I asked it, off course don’t want to make here like topic garbage for other users.

You misunderstood me or I could not make a fine self expression for my condition (English is not my language if can not explain it, sorry). I just give these image as only examples of my general problem faced off scripting on Godot until now.

I may not connection Nodes and its elements or classes how to direct my game assets/player/events/conditions etc.

In images:

  • first image one - how i decide on an element/func/method to use in any class? It’s related with Node that I used or related with my purpose and independent with used Node type.

nope

if not appear >> Imgur: The magic of the Internet

  • second one - Related/familiar with first one.

  • third one- made me shame :confused: I did not mean brief of the float, vector2 etc. sorry for word explain “aggh English” :D. I already know them from Python-Lua and Panda3D-Löve2d. I asked it for the arrange of the elements. Why this arrangement is there. Please correct me If I’m right.

void, Vector2, float shows type of element/method/func ?

get_node(), etc. shows method or func ?

And when I see the parentheses-argument of any func there I really stuck :frowning: An example:

Node get_node( NodePath path ) const

If it’s type is Node why we have to point out again another type NodePath into as an argument?

After Nodepath comes a parameter path that you greatly explained and I think it’s very Pythonish manner that I can write it how I want. Thanks a lot you.

What I believe that discussion will generally solve my stuck points how to read docs an how to use them as I need :slight_smile: .

*Godot is really great and I don’t want to go anywhere :wink:

linuxtopia | 2016-11-09 09:26

Nice :slight_smile:

I have made that comment because Godot is attracting a lot of diverse people lately, old, young, programmers, designers, and many others, also people that comes from engines that require zero knowledge and leaves them with zero knowledge too…


Godot scripting and design is object oriented and you can see the SceneTree as a container of Node instances.
All derive from Object, so, some methods you can use can go up to Object (but you may use Node methods more).

  1. If you check the script on Image 1, may see that enemy is probably a PackedScene (loaded with load or preload), a PackedScene is like a composite class made of many nodes and scripts (that you normally save as scn or tscn file).
    Once get an instance, these can be used like a any Node instance.

  2. That get_node method is inherited from the script class, it may extend a subclass of Node (first line of the script) and get the get_node from that.

  3. Here Node get_node( NodePath path ) const, as Zylann said is the form <return type> <method_name>(<parameter type> <parameter name>) says you get a Node (return type) with the method get_node and a parameter “path” of type NodePath.

If you search about the class NodePath, it will give you a long explanation but basically you can use a String as NodePath too.

If you do:

var my_node = get_node( "string_path_to_my_node" )

Then, my_node will store a reference to the Node instance at “string_path_to_my_node”

eons | 2016-11-09 16:33

:bust_in_silhouette: Reply From: Robster

I decided that I would choose Godot as my engine and I have very little programming experience.

I knew from previous attempts at making a game (where I did a lot of Copy/Paste) that I would never make a game properly unless I learned to program properly (or as well as I can).

So, I researched and read that GDScript is similar to Python.
I then went to Codecademy Python course ( https://www.codecademy.com/learn/python ) and did the whole course.

It took me a couple of weeks, maybe more, as I have to do it part time.
I had to do parts of it a few times.
I even had to skip some parts that just were too much for me (XOR operators etc).

When I came back to GDScript, it all made sense and worked. That’s how it was for me.
I’m still a very beginner programmer, but I am about to finish my first game, and I did it myself, with help and guidance of course from people here.

TLDR: Learn Python first. I hope that helps.

Thanks for your answer.

I’m already a Python programmer for years. My problem is on Gdscript how to use of its’ parts/elements/functions/methods etc those together to make a game. Can not combine them because no enough details/description/example about them in official docs. So we have to assume/predict how those works.

linuxtopia | 2016-11-17 21:49