This would be great, since the alternative to task spawning while true loops is RunService events, which if you donât time with deltaTime then you will execute your code every frame or physics tick and thatâs bad when you are making AIs
Due to devforum moderation I will not answer the first one but I will answer the second one.
I agree it looks way cleaner but honestly I doubt that they would actually add task.loop into the engine if we already got RunService and second thing honestly they wont add it unless big developers like adopt me creator needs it. (im sorry but thats the truth)
I agree with this one and only because if you put bool value the loop will start earlier but only if you do your stuff before task.wait()
while true do
--do something before task.wait
task.wait()
end
You are wrong and correct with this one task.wait() returns number. Try this out yourself. Thats why the loop doesnt get broken. If task.wait() didnt return anything the loop wouldânt be even running in first place.
Then another issue with this is that the author showed how easy it would be to just make a function for this. task.delay is a different story because it doesnât activate the function until that time passes but you can still cancel it before then.
Encouraging scripters to create infinite loops which do not self terminate, and then saying âitâs okay because they can always externally close the thread with task.cancelâ, seems like a bad idea. Iâd want a reliable means of aborting the loop.
Generally, when determining whether or not a new scripting feature is worth supporting, I feel itâs important to assess the impact it will have on the practices of scripters in aggregate. As it stands in this case, Iâm just not convinced that impact will be a net positive. You ask âwhy wouldnât weââIâm concerned with âwhy would weâ. Script architecture should primarily be event-driven. Creating infinite loops is usually seen as a last resort, as it tends to (though not necessarily) be indicative of wasteful design. If youâre implementing code similar to the proposed feature request, so often that you strongly feel it needs to be made an official addition to the task library, itâs perhaps worth evaluating whether or not your approach is efficacious to begin with.
I should add that I was careful to omit any technical reasoning as part of my initial response, as I didnât want to derail the discussion with subjects better suited to engineers. But to be very clear, task.cancel is not infallible. If you want this to be implemented, and you want a viable means of terminating the threads it creates, then you really want two features.
Iâm honestly not even entirely confident how to respond to this, because I feel itâs such a bad faith interpretation of my point. If thereâs an event, please use it. Writing your own code, to do whatever the event already checks for, is wasteful. Hence my statement,
Sorry for the late reply, I was away for the week.
The entire point of this request is to create infinite interval loops which do not self-terminate and are handled externally. Its syntax-sugar for a common idiom in game logic, just like Rustâs loop.
Every game runs on 1 main game loop, every single game. Even your âeventsâ are just running inside a loop but executed when a condition is met. You do not understand programming
While yes, most processes run off of a main loop, events such as key presses and other user input are handled asynchronously through interrupts.
And yes, you can definitely use a loop to poll constantly for input, or any change, though itâs incredibly inefficient and a waste of CPU cycles. Events run independently of any sort of interval and can be computed immediately by the CPU. They are not fired when a âcondition is met.â
Example
This is a loop that polls for user input and does something when it detects input.
while (true) do
task.wait(0.1);
if (isKeyDown(key)) then
doSomething();
end
Notice it will take at most 0.1s in order to read that the key has been pressed? Interrupts donât have this problem and will execute any code that listens for events immediately.
Overall, as @AskWisp said, use events. They were made with the goal in mind to alleviate the need for infinitely running loops that poll constantly for input.