|
|
|
|
Reply From: |
i_love_godot |
Like Ertain mentioned, yield
needs an object
first, then the string
of the signal you’re listening for:
yield(object_that_emits_the_signal_we_want, "signal_we_want")
If get_parent()._find_movement()
is being passed as the first argument to yield
, it needs to return
an object.
Thanks for responding I_love_godot, I appreciate the help. Bare with me as I’m still new to coding.
I thought a function is considered an object?
in this doc example, the yield
seems to have no problem accessing a function in place of an object
argument. Then there is a completed
signal it waits for. The doc’s imply that once the func button_func():
is finished, the yield
from my_func()
would automatically see that its GDstate changed and then resume itself. Is this correct? Or am I way off here?
func my_func():
yield(button_func(), "completed")
print("All buttons were pressed, hurray!")
func button_func():
yield($Button0, "pressed")
yield($Button1, "pressed")
Thank you again!
So you are calling yield
from within _find_movement()
too? And what signal is _find_movement()
listening for, and is it being emitted?
i_love_godot | 2019-12-11 16:13
At current, _find_movement()
has no yield
in itself and not listen for or emit any signals.
I just have a function yielding to it via: yield(get_parent()._find_movement(), "completed")
Or something like this.
Yes, so to solve the error you either need to return
an object, or yield
within the _find_movement()
function which would automatically return it’s frozen state.
i_love_godot | 2019-12-11 16:33
I see now. So, I can’t simply put a return at the end of an if statement inside _find_movement()
? Could I return a Vector3
? or a Null
?
or do I need to call a resume()
?
If you are going to return
from _find_movement()
then you need to return a signal emitting object, or yield
(which automatically returns the state which will emit “completed”)
It may be easier to explain what it is that you’re trying to achieve. Also, if you can post a larger code sample to get a better picture that would be helpful too.
i_love_godot | 2019-12-11 16:45
So I have this function:
func _movement1():
if y == 0:
return null
yield(get_parent()._find_movement(), "completed")
var target = translation + direction
$Tween2.interpolate_property(self, "translation", translation, target, 1, Tween.TRANS_LINEAR, Tween.EASE_IN)
if not $Tween2.is_active():
$Tween2.start()
then in the parent node I have:
func _find_movement():
if $AI.command == ["right"] and $Player.command == ["left"]:
if distancebetween == 5:
$Player.direction = Vector3()
$AI.direction = Vector3()
if distancebetween == 10:
$Player.direction = Vector3(0,0,2.5)
$AI.direction = Vector3(0,0,-2.5)
else:
$Player.direction = Vector3(0,0,5)
$AI.direction = Vector3(0,0,-5)
else:
return _proceed_as_normal()
func _proceed_as_normal():
$Player._getdirection()
$AI._storage()
Hope that helps.
It looks like you’re wanting to wait for the _find_movement()
function to complete before carrying on with the _movement1()
function. But from what I can see, the code seems pretty linear anyway and will be executed in sequence.
Have you tried removing the yield
call on line 3 of the _movement1()
function? It doesn’t seem necessary and is failing because neither _find_movement
nor _proceed_as_normal
actually yield
or return objects. Also, _find_movement
only explicitly returns sometimes, based on the if else
.
i_love_godot | 2019-12-11 17:40
Well I have two node with that same movement code calling to _find_movement()
, and _find_movement()
is longer than that, there’s 4 other identical if/else
statements that like first section, I just thought it would be redundant to post. Without the yield
, the two children: Player
and AI
, don’t seem to access the function at the same time and creates movement that doesn’t seem to be what I’m looking for. So I made _find_movement()
as kind of a pre-calculator for the tween. I figured a yield
function would be good cause it would process how to move based off the distance from each other, then send out the necessary movement variables.