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

Getter function is skipped without error if it has a required argument #19306

Closed
romlok opened this issue Jun 1, 2018 · 5 comments
Closed

Getter function is skipped without error if it has a required argument #19306

romlok opened this issue Jun 1, 2018 · 5 comments

Comments

@romlok
Copy link
Contributor

romlok commented Jun 1, 2018

Godot version:
3.0.2 (Steam)

OS/device including version:
Linux x64; X11; Debian Testing

Issue description:
If a GDScript variable is defined to use a getter function that has a required parameter (ie. one with no default value), the getter will not be called, and no error gets output.

I would expect an error to be logged in such a case.

Steps to reproduce:

class MyClass:
	var my_val = "default" setget ,my_getter
	
	func my_getter(oops):
		return "gotten"

func _ready():
	var foo = MyClass.new()
	print(foo.my_val)

Running this will print default rather than gotten, but not show any error message.

@mrcdk
Copy link
Contributor

mrcdk commented Jun 1, 2018

Getters functions don't have parameters. http://docs.godotengine.org/en/latest/getting_started/scripting/gdscript/gdscript_basics.html#setters-getters

This works:

class MyClass:
	var my_val = "default" setget ,my_getter
	
	func my_getter():
		return "gotten"

func _ready():
	var foo = MyClass.new()
	print(foo.my_val)

@romlok
Copy link
Contributor Author

romlok commented Jun 2, 2018

Ah, I guess my example's conclusion wasn't clear originally (now edited).
The issue isn't that the code doesn't work, but that the invalid code doesn't produce an error or warning message!

@swarnimarun
Copy link
Contributor

This actually works,

var val = "default" setget  ,get_me

func get_me(num = 0):
    return "awesome"

@bojidar-bg
Copy link
Contributor

The problem is not that the sample code does not work, the problem is that it does not produce an error.

@vnen
Copy link
Member

vnen commented Jul 22, 2018

Solved by #19264. It will now show an error in-editor if the getter or setter is invalid.

@vnen vnen closed this as completed Jul 22, 2018
@vnen vnen added this to the 3.1 milestone Jul 22, 2018
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

5 participants