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?
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?
check the command bar and run the game...see if it says "hello"
This doesn't answer the question.
This discussion is preserved as it was. New answers, comments, and votes are closed.
8 comments
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.
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.
It can be done in Haskell, which is a functional programming language.
" 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.
But sometimes a player doesn't intend to. That's why they asked me to create this feature to warn them.
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.
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
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.