Skip to content

Some GDScript behavior proposals #20634

@KoBeWi

Description

@KoBeWi

If you know me from Reddit, you might know that I'm in love with Ruby programming language XD

There are some things in Ruby (and some other languages too) that I miss in GDScript. Some of them might be controversial and they are all probably for Godot 4.0, but thought I'd write it for discussion purposes etc. So the list is:

  1. Different precedence for and/or/not and &&/||/!

I noticed that GDScript supports both and and &&. I was disappointed when I discovered they have same precedence. In Ruby, symbolic operators have precedence over word ones (so e.g. && is evaluated before and) and it's sometimes useful in complex conditions to avoid using brackets. I mean, since both of them are supported, they might be more than aliases.

  1. Treat 0 and [] as "true"

It works like this Ruby and LUA (and probably some other). I know GDScript takes heavily from Python, but that doesn't mean it should work exactly like that. There are people that take advantage of 0 being false, but there are also people that expect it to work otherwise. I for example like to make a null variable that has later number assigned and then I check if it exists and e.g. increment it. It was confusing to me few times when it didn't work. I know it's a matter of writing if variable != null, but still.

EDIT:
Apparently, zero vector is "false" too. Really? ¬_¬

  1. Allow for assignment inside condition statements

As stupid as it seems, it's useful when you are e.g. searching inside array. Normally you need to do

var found_one = find_in_array(something)
if found_one:
    found_one.do_something_etc()

This could be replaced by

if found_one = find_in_array(something):
    found_one.do_something_etc()

Maaybe in GDScript you'd need var after if, because otherwise it's less helpful, but right now you can't do something like this at all.

  1. Allow for chained assignement

Sometimes you want two variables to have one value. You need to do

b = a
c = a

While with chained assignment you could just do this:
b = c = a

Also in Ruby, you can go further:
a, b = c, d


I know that what am I proposing here are probably some useless quirks (arguably except the first one) that just make you save one line or few extra character. I'm not saying of course this MUST be a thing, I'm just writing this, because at some point I actually wanted to use each of them at least once, which means that there are some use cases where this might be useful for some people. While first two might break some scripts, 3 and 4 don't really affect anything other than giving more options.

Any thoughts? >.>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions