Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I check if a function finishes or not?

Hello. I would like to see if a function finishes or not. For example, this passed through

while true do wait() end

would return false, because it never finishes. But this

print("hello")

would return true, because it does finish. Any ideas?

8 comments

0

Not sure you can. Why would you need to? You can always spawn() a function so that even if it never does end, the script could still continue.

0

I'm making a Script Builder place, and I want the player to know their script won't finish and ask if they still want to execute it. This is a highly demanded feature people have asked for.

0

It can be done in Haskell, which is a functional programming language.

0

" I want the player to know their script won't finish" Infinite loops are usually not an error but a standard practice in all games to keep things moving. There's no need for that.

0

But sometimes a player doesn't intend to. That's why they asked me to create this feature to warn them.

0

I can only think of possible ways to be if you can scan the code and detect if a while loop or any loop that wont end is being used. Like if a condition will never be met by searching for key words, don't know if this helps you though.

0

I hate to be the one to break it to you, but this is impossible. This is a variation of the infamous 'Halting Problem' by Alan Turing, the father of theoretical computer science. https://en.wikipedia.org/wiki/Halting_problem

0

One way to understand it in this context is thus: in the general case, you can only check if a loop terminates by running the loop. But if the loop doesn't terminate, then neither will the program which is trying to check if it terminates.

1 answer

check the command bar and run the game...see if it says "hello"

1 comment

0

This doesn't answer the question.

This discussion is preserved as it was. New answers, comments, and votes are closed.