<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>GDScript on Terrible Software</title>
    <link>https://terriblesoftware.dev/tags/gdscript/</link>
    <description>Recent content in GDScript on Terrible Software</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Wed, 11 Dec 2024 09:34:12 +0800</lastBuildDate>
    <atom:link href="https://terriblesoftware.dev/tags/gdscript/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>TDIL: The Magic of Callable.bind in GDScript</title>
      <link>https://terriblesoftware.dev/en/posts/adding-data-to-signals-gdscript/</link>
      <pubDate>Wed, 11 Dec 2024 09:34:12 +0800</pubDate>
      <guid>https://terriblesoftware.dev/en/posts/adding-data-to-signals-gdscript/</guid>
      <description>&lt;h1 id=&#34;tdil-the-magic-of-callablebind-in-gdscript&#34;&gt;TDIL: The Magic of Callable.bind in GDScript&lt;/h1&gt;&#xA;&lt;p&gt;Today I learned (TDIL) about a super helpful feature in GDScript: Callable.bind. If you&amp;rsquo;re working with signals in Godot and find yourself needing to pass additional data to a single handler, Callable.bind is your new best friend.&lt;/p&gt;&#xA;&lt;h2 id=&#34;the-problem&#34;&gt;The Problem&lt;/h2&gt;&#xA;&lt;p&gt;In many UI setups, you might have multiple buttons that trigger the same function. However, these buttons often represent different actions or carry unique context. For example:&#xA;A list of character abilities with each button corresponding to a specific skill.&#xA;A menu system where each button navigates to a different scene or executes a unique task.&#xA;The usual approach is to connect each button&amp;rsquo;s pressed signal to the same function. But how do you tell which button triggered the signal? And what if you need to pass more data (e.g., an ID, name, or reference) to your handler?&lt;/p&gt;</description>
    </item>
    <item>
      <title>Terrian 3D: Doing in game actions based on the texture the character is standing on</title>
      <link>https://terriblesoftware.dev/en/posts/detecting-texture-under-character-terrian-3d/</link>
      <pubDate>Wed, 11 Dec 2024 09:34:12 +0800</pubDate>
      <guid>https://terriblesoftware.dev/en/posts/detecting-texture-under-character-terrian-3d/</guid>
      <description>&lt;h1 id=&#34;terrian-3d-doing-in-game-actions-based-on-the-texture-the-character-is-standing-on&#34;&gt;Terrian 3D: Doing in game actions based on the texture the character is standing on&lt;/h1&gt;&#xA;&lt;p&gt;Enhance gameplay by triggering actions based on terrain textures. Use &lt;a href=&#34;https://github.com/TokisanGames/Terrain3D&#34;&gt;Terrian3D&lt;/a&gt; to fetch texture IDs at the player&amp;rsquo;s position:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://terrain3d.readthedocs.io/en/stable/api/class_terrain3ddata.html#class-terrain3ddata-method-get-texture-id&#34;&gt;get_texture_id()&lt;/a&gt; returns a Vector3 containg &lt;code&gt;Vector3(base texture id, overlay id, blend value)&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-gdscript&#34; data-lang=&#34;gdscript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;@&lt;/span&gt;export &lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; terrian:Terrain3D)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;_physics_process&lt;/span&gt;(_delta: &lt;span style=&#34;color:#66d9ef&#34;&gt;float&lt;/span&gt;) &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;void&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; texture_pos: &lt;span style=&#34;color:#a6e22e&#34;&gt;Vector3&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; terrian&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;data&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;get_texture_id&lt;/span&gt;(PlayerManager&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;get_player&lt;/span&gt;()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;get_position&lt;/span&gt;())&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        print_debug(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Texture ID: &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{0}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;format&lt;/span&gt;([texture_pos]))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; base_texture_id &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;int&lt;/span&gt;(texture_info&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;x)  &lt;span style=&#34;color:#75715e&#34;&gt;# Base texture ID (e.g., 1 = Grass, 2 = Dirt, 3 = Sand)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# base_texture_id is the index of the texture in the terrain from the Terrian3D inspector&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# in my case 1 is grass, 2 is dirt, 3 is sand&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        print_debug(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Base Texture ID: &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{0}, Overlay ID: {1}, Blend: {2}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;format&lt;/span&gt;([base_texture_id, texture_info&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;y, texture_info&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;z]))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;match&lt;/span&gt; base_texture_id:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                print_debug(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Grass&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#75715e&#34;&gt;# Trigger grass-related actions&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                print_debug(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Dirt&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#75715e&#34;&gt;# Trigger dirt-related actions&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                print_debug(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Sand&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#75715e&#34;&gt;# Trigger sand-related actions&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use this to adjust movement speed, trigger sounds, or create particle effects for immersive gameplay. It&amp;rsquo;s simple yet powerful!&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
