[Fixed] WaitForChild() doesn't allow integers anymore

Oops, I thought you were referring to OP. Completely forgot about the scripter MisterObvious mentioned.

string coercion > poor programming practices
poor programming practices > pcall/ypcall
string coercion > poor programming practices > pcall/ypcall

I say string coercion is a bad programming practice and the API shouldn’t enable it. You say/imply bad programming practices enabled by the API are fine because of the pcall/ypcall situation and there’s no reason to fix them. I say problems shouldn’t be able to accumulate and you need to start getting rid of them somewhere. Am I missing something? Not sure where the confusion is.

What

The only reason a timeout argument is useful is because it warns you about issues you didn’t plan to happen. You’re not going to manually enable timeout for something you didn’t plan to happen. I hope this is temporary or unintentional.

Edit: It might be disabled. I put this in an empty script workspace:WaitForChild("Doesn'tExist",1) in workspace, and when I went into play solo it never gave me a warning even though I manually defined the timeout.

Ah, ok. I wasn’t trying to justify string coercion using pcall/ypcall as an example. I was trying to humorously bring up the fact that they have simplified the API before. It seems I need to work on the delivery.

1 Like

After testing WaitForChild with the related FFlag enabled, I can confirm that the argument does behave as if it has a default value. So there is a problem with WaitForChild’s API, which is that the timeOut argument is not indicated as being optional.

I can also say that, for calls that don’t specify the timeout argument, a warning will be thrown after several seconds of waiting.

1 Like

I manually indicated that its optional on the wiki in the mean time.

This is because WaitForChild is bound more directly to the Lua stack that normal in order to provide a stack-trace with the warning. This is also why integers did not coerce.

Sorry for any inconvenience.

[Method] instance Instance:WaitForChild(string ChildName [, number timeOut=nil])

Behavior when timeout is undefined

If timeout is undefined, then WaitForChild will yield until the child is found. If the yield time is longer than 5 seconds, a warning will be emitted with the parent’s full name and the child’s name.

Behavior when timeout is defined

If timeout is defined, then WaitForChild will yield until the child is found or until the timeout is reached, upon which WaitForChild will return nil if the child does not exist.

3 Likes

Thanks, I’ll note that on the wiki page.

I see. So now that we have a function that yields, but isn’t a YieldFunction, what is a YieldFunction?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.