I know you can call functions inside another function, but can I call a function inside itself?
For more context, basically I want the script to choose a random piece of land, and create land around that existing piece of land by checking the surrounding areas to see if land is there. If there is no spot for land to be created, I want it to run the whole function again so it chooses a different piece of land. Would something like this work:
function makeLand()
if landCanBePlacedThere then
--make the land and all that
else
makeLand()
end
2 Likes
Yes, recursive functions are a thing that exist on pretty much any half-decent programming/scripting language.
1 Like
also another similar to this but i dont want a whole new post on it
lets say i want to run the function and want to use whatever it returns
if i say
local thing = myFunction()
in doing that, does that also call the function? because the function involves random number generation and i want to be able to use the results of that one specific time the function was called
Yes it does, if you add (...)
, "..."
or {...}
at the end of a function without using a semicolon or identifier to separate them, it will call the function.