The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

–2 votes

For some reason godot does not like the use of kebab-case in a function name. I won't be able to use godot if this isn't an option.

func _ready(): 
  test-function()

func test-function():
   pass

The above code returns an error. Is there any workarounds to this?

in Engine by (10 points)

1 Answer

+2 votes

The - character is the subtraction operator in GDScript, so no, you can't use it in a variable/function name.

The GDScript style guide prescribes snake_case for variables and functions. The best "workaround" would be to stick to test_function() as that will match the style of all the built-in function names.

by (22,191 points)

As I stated in my original post, I need to be able to use kebab case. I'm surprised Godot, as an open source engine, is this Authoritarian about naming conventions. The way you've stated it, it seems my only options are to go into the source code and change the subtraction operator, or download Unity.

I'm not sure how that's going to help you, as - is not an allowed character in C# either (or any other language I can think of besides Lisp).

Yep, I'll second what kidscancode already said. You'll be hard-pressed to find a mainstream language that supports a dash character in a function name. With that in mind, I assume you'll need to rethink your "I need to be able to use kebab case" statement.

Why is that particular convention such a hard requirement in your case?

Thanks, i'll look into lisp

jgodfrey, there is an organization I am attempting to join and they require new recruits to create a game wherein code is neat and all names follow their standards and practices.

Lisp is not going to be much use for you if you're interested in game development. It would be more useful to ask what possible reason this "organization" has for such a strange policy, and what possible languages they could be prescribing.

Note there are very good reasons that the majority of programming languages disallow - in identifiers (and also any other operators like + / & etc). Consider the following:

var a = 5
var b = 2
var a-b = 1
var c = a-b  # what is c? 1 or 3?

Allowing this would make it impossible for the compiler to know whether you meant a variable name or an operation there.

Huh... Ok. It seems really strange that they'd adopt (and require) a naming convention that inherently eliminates most mainstream languages.

Anyway, good luck.

The organization is mainly for fun, nothing serious.
There's no good reason why the compiler can't just interpret everything after "func " and before ":" as a name. For your example above, I don't see any reason why it would be 3. The only confusion I could imagine is this case:

var a = 1
var b = 2
var a-b = a-b

but I don't see how this affects functions

but I don't see how this affects functions

var a = 1

func b():
    return 2

func a-b():
    return 3

func _ready():
    print(a-b())

So, what will this print then? -1 or 3? How do you know?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.