<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Engels Garcia</title>
    <description>The latest articles on DEV Community by Engels Garcia (@engels_garcia_d67e58ea9d1).</description>
    <link>https://dev.to/engels_garcia_d67e58ea9d1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2592609%2Fcc9060ca-fe5e-4e05-bfaf-88b8bb883057.jpg</url>
      <title>DEV Community: Engels Garcia</title>
      <link>https://dev.to/engels_garcia_d67e58ea9d1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/engels_garcia_d67e58ea9d1"/>
    <language>en</language>
    <item>
      <title>Moving into the niche! From JavaScript to GDScript</title>
      <dc:creator>Engels Garcia</dc:creator>
      <pubDate>Thu, 19 Dec 2024 19:01:13 +0000</pubDate>
      <link>https://dev.to/engels_garcia_d67e58ea9d1/moving-into-the-niche-from-javascript-to-gdscript-1m9i</link>
      <guid>https://dev.to/engels_garcia_d67e58ea9d1/moving-into-the-niche-from-javascript-to-gdscript-1m9i</guid>
      <description>&lt;p&gt;If you already know JavaScript, you’ve most likely experienced the world of web development and are familiar with many programming concepts and best practices. Now if you’re here that means you want to dive into game development. As per the title, I’ll be telling you about this language called GDScript, it is used for scripting in the Godot game engine. Whether you’re looking to develop 2D or 3D games, GDScript is an accessible and powerful tool to make it easy to get into game development. &lt;/p&gt;

&lt;h3&gt;
  
  
  Why Should I Learn GDScript?
&lt;/h3&gt;

&lt;p&gt;First of all, let me tell you what GDScript is. GDScript is a high-level, dynamically typed programming language designed specifically for Godot, an open-source and feature-rich game engine. The language is optimized for rapid game development and is tightly integrated into the Godot environment. As a JavaScript developer, GDScript might feel familiar in some ways, especially because both languages share an easy-to-understand syntax. This makes GDScript a great choice for transitioning into game development.&lt;/p&gt;

&lt;p&gt;Now let me give you some reasons to learn this language&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Specific for Game Development&lt;/strong&gt;: GDScript is tailor-made for developing games and lets you access Godot’s most powerful features such as scene management, physics, etc. all using simple and readable code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Beginner Friendly&lt;/strong&gt;: this point is self-explanatory. Godot is incredibly beginner-friendly and pretty fast to pick up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Popularity&lt;/strong&gt;: Godot’s popularity has been growing rapidly. It’s known for being free and open-source with a strong community of developers and contributors.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Syntax Differences: GDScript vs. JavaScript
&lt;/h3&gt;

&lt;p&gt;While GDScript shares several similarities with JavaScript, it has its unique features that cater specifically to game development. Let’s compare key parts of the syntax:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Scripting for Nodes
&lt;/h3&gt;

&lt;p&gt;Godot keeps information in elements called &lt;code&gt;scenes&lt;/code&gt;, which have a tree-like structure of elements called &lt;code&gt;nodes&lt;/code&gt;, which can also be scenes themselves. GDScript files are created and attached to these nodes. All files have the &lt;strong&gt;&lt;code&gt;extends&lt;/code&gt;&lt;/strong&gt; keyword at the very first line, which defines the class this script inherits or extends. In this example, it's &lt;strong&gt;&lt;code&gt;Sprite2D&lt;/code&gt;&lt;/strong&gt;, meaning our script will get access to all the properties and child nodes of the Sprite2D node.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends Sprite2D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Syntax Differences
&lt;/h3&gt;

&lt;p&gt;Before we move onto more GDScript code, let’s briefly look at the most notable differences in syntax between GDScript and JavaScript focusing on GDScript:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For the very basics, variables are declared with the &lt;code&gt;var&lt;/code&gt; keyword with no &lt;code&gt;const&lt;/code&gt; or &lt;code&gt;let&lt;/code&gt; variations. Logging into the console is done using the &lt;code&gt;print&lt;/code&gt; keyword as opposed to the &lt;code&gt;console.log()&lt;/code&gt; function. Finally, comments are made using the syntax element &lt;code&gt;#&lt;/code&gt; instead of &lt;code&gt;//&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var greet = "hi"
print(greet) # prints "hi"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// logs "hi"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Functions in GDScript are declared using the &lt;code&gt;func&lt;/code&gt; keyword, shortening the common function declaration with the &lt;code&gt;function&lt;/code&gt; keyword or arrow function syntax.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func greet():
  print("hi")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// or&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Conditionals are more similar to Python in that they do not use braces but indentation instead.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if true:
  print(true)
elif 5 &amp;gt; 10:
  print("this will never run")
else:
  print(false)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;this will never run&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;GDScript uses &lt;code&gt;for&lt;/code&gt; with ranges instead of traditional &lt;code&gt;for&lt;/code&gt; or &lt;code&gt;for of&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# count from 0 to 4
for i in range(5):
  print(i)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// count from 0 to 4&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Starting Functions
&lt;/h3&gt;

&lt;p&gt;Every GDScript files also have 2 functions upon creation: &lt;code&gt;_ready&lt;/code&gt; and &lt;code&gt;_process&lt;/code&gt;. Starting with the &lt;code&gt;_ready&lt;/code&gt; function, it runs as soon as the node the file is attached to gets rendered on the scene. On the other hand, the &lt;code&gt;_process&lt;/code&gt; function runs every frame and has a parameter called &lt;code&gt;delta&lt;/code&gt; which is the amount of time the previous frame took to complete.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extends Node

func _ready() -&amp;gt; void:
  pass

func _process(delta: float) -&amp;gt; void:
  pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, several things are happening in this script. First, the script is attached to a blank node but this is irrelevant for this example. Then the &lt;code&gt;_ready&lt;/code&gt; and &lt;code&gt;_process&lt;/code&gt; functions are both defined as void functions, meaning they do not return anything. Note that the &lt;code&gt;_process&lt;/code&gt; function has the &lt;code&gt;delta&lt;/code&gt; parameter which is a float. Unlike in JavaScript, Godot throws an error if you have an empty function, in this example notice how both functions have the &lt;code&gt;pass&lt;/code&gt; keyword on them which is a skip to avoid getting such errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Tips For Learning&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Understand Godot’s Architecture&lt;/strong&gt;: GDScript is tightly integrated with Godot’s scene system. Familiarize yourself with how Godot handles scenes and nodes to truly take advantage of GDScript.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Your JavaScript Knowledge&lt;/strong&gt;: If you’re already proficient in JavaScript, use your understanding of concepts like variables, functions, and conditionals to help you learn GDScript. The biggest difference will likely be adjusting to indentation-based syntax and the specific features of Godot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice with Small Projects&lt;/strong&gt;: Start by creating simple projects in Godot, such as a 2D platformer, or go with the 20 Games Challenge. This will help you get accustomed to the engine’s tools and the syntax of GDScript.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use The Help Function&lt;/strong&gt;: Godot includes a help search bar from which you can find documentation on syntax among other elements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://20_games_challenge.gitlab.io/" rel="noopener noreferrer"&gt;20 Games Challenge&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gdquest.com/" rel="noopener noreferrer"&gt;GDQuest&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.godotengine.org/en/stable/getting_started/first_2d_game/index.html" rel="noopener noreferrer"&gt;Your First 2D Game Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;GDScript offers a smooth transition for JavaScript developers who are looking to dive into game development with the Godot engine. With its familiar syntax and powerful, game-specific features, it’s an excellent language for developing both 2D and 3D games. While it does have unique aspects such as its integration with Godot’s framework, your JavaScript knowledge will serve you as a solid foundation to quickly pick up GDScript. With practice and exploration, you’ll be on your way to bringing your ideas to life. Good luck on your journey into the world of game development!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
