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

TreeItem call_recursive method nonexistent #41493

Closed
Koyper opened this issue Aug 24, 2020 · 7 comments · Fixed by #42724
Closed

TreeItem call_recursive method nonexistent #41493

Koyper opened this issue Aug 24, 2020 · 7 comments · Fixed by #42724

Comments

@Koyper
Copy link
Contributor

Koyper commented Aug 24, 2020

Godot version:
3.2.2

OS/device including version:
Mac OS 10.14.5

Issue description:
returns error message:
"Invalid call. Nonexistent function 'call_recursive' in base TreeItem

call_recursive is listed in TreeItem methods in the docs

Steps to reproduce:
Call the method on any TreeItem instance.

Minimal reproduction project:

@Xrayez
Copy link
Contributor

Xrayez commented Aug 24, 2020

Make sure you call the right (existing) method in TreeItem as parameter, also by supplying any required arguments:

extends Node2D

func _ready():
	var item = $Tree.create_item()
	item.call_recursive("set_collapsed", true)

But yeah the error message is misleading, the error should report the method name specified via the argument, and not the caller.

You can reproduce this issue with something like: item.call_recursive("blabla")

@Koyper
Copy link
Contributor Author

Koyper commented Aug 24, 2020

Thanks, that works and I now know the methods must exist in TreeItem. I was calling a custom function. The docs imply that any method can be called, so a doc edit would clear that up.

@Xrayez
Copy link
Contributor

Xrayez commented Aug 24, 2020

I was calling a custom function.

Do you mean that you extend TreeItem via script?

If that's the case, then perhaps it can be made so that script methods could also be called using this method in the engine.

@Koyper
Copy link
Contributor Author

Koyper commented Aug 24, 2020

I had extended Tree via script and called that method - I didn't try extending TreeItem - is that intended to work?

@Xrayez
Copy link
Contributor

Xrayez commented Aug 24, 2020

@Koyper sorry, I wrongly assumed TreeItem has some public methods which could also allow you to add arbitrary items (which could be potentially scripted), there's only Tree.create_item() and not Tree.add_item(), so yeah I think it's not possible to do this. Then again this wouldn't work if you extend Tree via script either, because the methods made for the Tree wouldn't be available for created tree items in any case.

So I think there's no way to add new methods for tree items specifically, you could only use things like TreeItem.set_meta() which are available to every Object derived class (or rather TreeItem.set_metadata). You can in theory embed other scripted objects as meta objects with your methods of interest as a workaround, but this is likely too complex anyway.

@Koyper
Copy link
Contributor Author

Koyper commented Aug 24, 2020

Thanks so much for your detailed replies. I have the tree hierarchy mirrored in data, and have recursive functions to manage the hierarchy (a less-trivial task than one would initially assume), so I worked around it, though there are cases where having it scriptable would be helpful. I'll be able to use the existing functions with the call_recursive in any case, now that I know the limitations.

@theoway
Copy link
Contributor

theoway commented Oct 2, 2020

Make sure you call the right (existing) method in TreeItem as parameter, also by supplying any required arguments:

extends Node2D

func _ready():
	var item = $Tree.create_item()
	item.call_recursive("set_collapsed", true)

But yeah the error message is misleading, the error should report the method name specified via the argument, and not the caller.

You can reproduce this issue with something like: item.call_recursive("blabla")

I'll make a PR then, to fix the error message.

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