GDScript 2.0: Unknown Function `convert()` in @GDScript scope
Godot version
4.0-beta1
System information
Zorin OS-16, Intel hd 5500HD
Issue description
Some Global Scope functions are "unknown" in GDscript. "convert", function is one such function. Not sure how/why this is possible.

Steps to reproduce
Use the convert function to any meaningful task should trigger the error.
Minimal reproduction project
No response
Seems related (same?) to #5523
@KoBeWi. It indeed looks to be the same. I guess a decision whether to remove or improve it was not reached since this was from a year ago. I say just nuke the thing. One less "conversion" function to worry about among the many we already have. I guess not many used it either.
I have the same issue, I can't convert a variant from a Javascirpt.eval() rerturn to int in any way. This is VERY urgent for me so any kind of advice would be appreciated. I'm trying to get a browser parameter value.
@QushyQushy just type cast it. Use the as keyword or int(variant) or if you want some convoluted way use var_to_str() and then convert the str to int
@QushyQushy just type cast it. Use the
askeyword orint(variant)or if you want some convoluted way usevar_to_str()and then convert the str to int
It returns null sometimes so that was the issue. I just used an if statement.
Just wanted to point out that int("2") for example does not actually work to convert a string to number, I needed to also use str_to_var, so honestly either a working convert or a better casting system sound like a necessity to me.
It's not very clear in the screenshots what types you are actually trying to convert and how.
But if you have a string like "2" that you want to convert to an int, use "2".to_int().
PLEASE don't remove the convert function, i need it too! It is very helpfull to have such utility.
@MikeSchulze what are you using it for?
@MikeSchulze what are you using it for?
I build the plugin GdUnit3 and current on migrate to Godot4. I have a GdScript parser implemented to parse out a function descriptor to hold all informations about all argument type and defaults.
class_name GdFunctionArgument
extends RefCounted
var _name: String
var _type: int
var _default_value :Variant
const UNDEFINED :Variant = "<-NO_ARG->"
const ARG_PARAMETERIZED_TEST = "test_parameters"
func _init(name :String, type :int = TYPE_MAX, default_value :Variant = UNDEFINED):
_name = name
_type = type
_default_value = default_value
func name() -> String:
return _name
func default() -> Variant:
prints("get converted type %s of %s" % [_type, _default_value])
return convert(_default_value, _type)
By nature, the parser reads everything from a file as string and I have to convert the default arguments final from string to the real type.
Did you try using str2var (3.x) / str_to_var (4.x)? This is the supported way to convert a string representation to a Variant.
Yes i use currently str_to_var but this is not save enough, i wrote my own convert now to handle the edge cases as well.
e.i. to convert a string "1" could be mean int could also mean a float.
I have the type already extracted from the scripts and want to convert in the right value.
So have a convert function with a type as argument would be great.
In #70080 I am proposing to replace the existing convert method with a new type_convert method. This method will always succeed and it also has a clearer name to make it obvious that we are converting types.