Is there a way to avoid recursion?
Asked by
6 years ago Edited 6 years ago
Why do I have a recursive function?
In my script, I have this function that checks if there is a value called "Status".
NOTE: THERE IS CODE IN BETWEEN THE LOOPS AND IF STATEMENTS THAT I DIDN'T SHOW
01 | local function recursive(model) |
02 | for _,child in pairs (model:GetChildren()) do |
03 | for _,descendant in pairs (child:GetChildren()) do |
04 | if descendant:IsA( "StringValue" ) and descendant.Name:lower() = = "status" then |
05 | if string.sub(descendant.Value, 1 , 4 ):lower() = = "jump" then |
07 | elseif string.sub(descendant.Value, 1 , 5 ):lower() = = "speed" then |
09 | elseif string.sub(descendant.Value, 1 , 4 ):lower() = = "kill" then |
What is newMap?
newMap is a map that is being cloned into Workspace. I have declared this variable before so you don't have to worry about that.
Status
Status is supposed be in a model, not added.
As you can see, I am using recursion. However, I want to avoid using recursion as much as possible for good performance in my game. Is there an alternative to recursion?