-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
[Godot4] return GDScriptFunctionState in someway #3469
Comments
I am sorry but there seems to be no |
@CsloudX Please fill in all the questions in the issue template instead of just leaving a |
Pretty sure it's still possible or at least there is a workaround for that. If you share some minimal 3.x project with example of your use-case I could try porting it to 4.0. |
|
So after reading godotengine/godot#53822 (comment) I think there is some misunderstanding how coroutines work in 4.0. Basically, any function will now always return its intended value (int, String, Object, whatever), whether it's a coroutine or not. If you call a function and try to use its return value and the function is a coroutine, you need to wait before it finishes to be able to obtain the final result. It's very logical and it's the reason why function state is no longer a thing. Coroutines just don't return midway, they actually pause execution. So implementing this proposal is impossible, because it's against how the new GDScript works. But as I said, there are workarounds. You can create your own object that will await the result and emit a signal. |
I thought coroutines and non-coroutines would work the same here. In the sense that the value to the right of
class AwaitAllCaller:
signal all_completed()
var _funcs: Array[Callable]
var _completed := false
func _init(funcs: Array[Callable]):
_funcs = funcs
for f in funcs:
_call_func(f)
func _call_func(f: Callable) -> void:
await f.call()
_funcs.erase(f) # For some reason, it doesn't work.
if _funcs.is_empty() and not _completed:
all_completed.emit()
_completed = true
func _ready() -> void:
await AwaitAllCaller.new([f1, f2, f3.bind("test")]).all_completed
print("All functions completed!") |
I think that comment is a bit misleading. Although maybe I'm wrong, I didn't delve into the new GDScript that much. |
I'm sorry, YES, I mean |
OK, thanks |
Thanks for @dalexeev , I agree with that, and can I close the comment? |
YES, I like this implement too, but need fix theis earse bug first. |
Describe the project you are working on
NO-GAME APP
Describe the problem or limitation you are having in your project
I want implement this:
In Godot3.X, I can code like this:
I like this codes, But in Godot4, I Can't get GDScriptsState so I can't implement it!
Describe the feature / enhancement and how it helps to overcome the problem or limitation
If not use await keyword, try return GDScriptsFunctionState
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
If implement like that, I can code like this:
If this enhancement will not be used often, can it be worked around with a few lines of script?
In GODOT4, I can't implement this
Is there a reason why this should be core and not an add-on in the asset library?
It's GDScript syntax, so can't a add-on
The text was updated successfully, but these errors were encountered: