This is a very confusing question, but let's imagine this scenario.
There is two tables. However, inside the table contains itself a table of the other.
local digitsofpi = {3,1,4,1,5}
local table = {"These "," are "," digits "," of Pi",digitofpi," very", "interesting"}
What if I wanted to do a function, named "printAllContent()" with one parameter which is a table, where I run through the table's content and print what is inside and a user input is necessary every time you progress through the table, such as clicking the screen.
function printAllContent(table)
for i,v in pairs(table) do
print(v)
repeat
wait()
until UserInput -- This line isn't proper code, it just yields until the user responds
end
end
However, when you come across a table, you will then call the same function, "printAllContent()", however this time you put the table inside the table as the parameter of the function. Now the function looks like this.
function printAllContent(table)
for i,v in pairs(table) do
if isTable(v) then -- This is a made up function which returns if the parameter is a table
printAllContent(v)
end
print(v)
repeat
wait()
until UserInput -- This line isn't proper code, it just yields until the user responds
end
end
This way, it will run through all of the content of the table including the embedded table.
The problem here is that let's say that the user has the option to quit in the middle of the function using another function, "quitPrinting()". This function is connected to an event where a user presses a U.I button on the screen
For example, let's say the printAllContent() function is called and you prematurely end the process by calling "quitPrinting()" when you get to '4'
These
are
digits
of
Pi
3
1
4
And you called the function,printAllContent(), again and you get this
These
very
are
interesting
digits
of
Pi
3
1
4
1
5
very
interesting
While the embedded function was closed, every function call that came before it continued to print. How do I, essentially, stop all function when one recursive function ends.
I hope this made sense, this is a very difficult problem to describe.
For additional context. I am making my own npc dialog system and I'm using tables as the script for the npc tor read, and I also have a button where the player can leave the conversation at any time.
tl;dr In a recursive function, how do I stop all previous functions.

1 comment
Ah, that's a shame, I thought there would be a more elegant answer. Thank you nonetheless!