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

Can't access any methods of GDScript classes (except .new()) unless you first cast them as Script or GDScript #76414

Open
NotDaze opened this issue Apr 24, 2023 · 5 comments

Comments

@NotDaze
Copy link

NotDaze commented Apr 24, 2023

Godot version

4.0.2

System information

Windows 11

Issue description

You can't use any methods of a class (except .new()) unless you explicitly cast it to Script or GDScript.

class Example:
	pass;

func _init():
	print(Example is GDScript); # true
	print((Example as GDScript).has_source_code()); # false
	print((Example as Script).has_source_code()); # false
	print(Example.has_source_code()); # error
	
	var typed_implicit := Example; # also doesn't work
	print(typed_implicit.has_source_code()); # error

There is also some other... strangeness going on.

func _init():
	var untyped = Example;
	
	# print(untyped.has_source_code()); # error
	# print(Example.has_source_code); # error
	print(untyped.has_source_code); # works??
	print(untyped.has_source_code.call()); # also works??
	print(Example["has_source_code"].call()); # also works

Likely related to #73140

Edit: You actually can't even access .new() outside of calling it.

func _init():
	
	print(Example.new()); # works, of course
	print(Example["new"]); # works
	print(Example.new); # error

Also, everything works out the same if Example is a class_name in its own file instead of an inner class.

Steps to reproduce

Attempt to access the methods of a GDScript-based class without first casting it to Script or GDScript.

Minimal reproduction project

MRP.zip

@YuriSizov
Copy link
Contributor

YuriSizov commented Apr 24, 2023

Example in your example is neither Script nor GDScript, it's RefCounted (or Reference in 3.x).

print(Example is GDScript); # true

seems like an error to me, since it's not even a script class, it's an inner class.

@NotDaze
Copy link
Author

NotDaze commented Apr 24, 2023

Everything is still the same if Example is a class_name in a separate file. Also, print(Example.new().get_script()) prints a GDScript object, identical to what happens if Example is its own file. It appears that inner class objects themselves do extend GDScript.

@YuriSizov
Copy link
Contributor

No, they don't. And if they somehow do, it's an error. If you don't specify any base type, RefCounted is used. But there is trickery to make it script-based types work that expose some of those GDScript methods, like new().

@NotDaze
Copy link
Author

NotDaze commented Apr 24, 2023

The object you get from Example.new() does not implement GDScript. Example itself absolutely does. I don't know if that's an error, but it is 100% what I am seeing.

@YuriSizov
Copy link
Contributor

Yes, you are correct, of course. I got confused.

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

No branches or pull requests

2 participants