Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Invalid call. Nonexistent built-in function 'convert'." from script #5523

Open
bojidar-bg opened this issue Jul 2, 2016 · 6 comments
Open

Comments

@bojidar-bg
Copy link
Contributor

bojidar-bg commented Jul 2, 2016

Operating system or device - Godot version:
Arch linux -- Godot master ( 119cd5d )

Issue description (what happened, and what was expected):
I was playing around with some code until Invalid call. Nonexistent built-in function 'convert'. came up.

Steps to reproduce:

  • Add this script to a random node:
func _ready():
    print(convert("1,2", TYPE_VECTOR2))
  • Hit play and watch.

Edit: looks like one can't convert a String to a Vector2 -- oops! Anyway, the error message is as misleading as possible, and would be nice if it is fixed ^^

Link to minimal example project (optional but very welcome):

@vnen
Copy link
Member

vnen commented Jul 2, 2016

This happens because when the constructor fails, it returns a CALL_ERROR_INVALID_METHOD: https://github.com/godotengine/godot/blob/master/core/variant_call.cpp#L1133

Which for GDScript means a non-existent function:

} else if (p_err.error==Variant::CallError::CALL_ERROR_INVALID_METHOD) {

@bojidar-bg
Copy link
Contributor Author

Anyway, the message is very, very misleading ^^

@bojidar-bg bojidar-bg added enhancement and removed bug labels Jul 2, 2016
@Piet-G
Copy link
Contributor

Piet-G commented Sep 19, 2018

Still relevant in master

@KoBeWi
Copy link
Member

KoBeWi commented Mar 6, 2021

In 0524853 the error says Invalid call for function "Convert". IMO we should just remove this function, casting is super-simple to do and more reliable. The fact that I learned about convert() from this issue doesn't help.

@Xrayez
Copy link
Contributor

Xrayez commented Mar 6, 2021

If casting allows to convert all supported Variant types, then yeah I think it makes sense to remove convert from GDScript, unless it's not exactly the same thing.

The following produces equivalent result (3.2):

func _ready():
	print("Vector2(0, 0)" as int) # prints 200
	print(convert("Vector2(0, 0)", TYPE_INT)) # prints 200

So I suspect casting uses the same conversion mechanism then (not sure why or how it converted Vector2(0, 0) to 200, though).

@KoBeWi
Copy link
Member

KoBeWi commented Mar 6, 2021

(not sure why or how it converted Vector2(0, 0) to 200, though).

Vector2(0, 0) -> 200
That's how int("str") method works. So there are 3 ways to convert stuff right now.

Also I tried using convert() on master and it's broken. E.g. it can't convert string to int.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants