What's the point of the function end) or end?

I’m trying to answer myself the point of end) or end. I’ve been wanting to know and I’ve been questioning myself:
What’s the point of end?
This might be the wrong topic.

If end is to end the script then: Why can’t we have multiple ends?
After answering that, can you also tell me the difference between end and end)?

Again, I think this might be in the wrong topic so please tell me if it is.

2 Likes

you have to close off your statements, functions, or loops
this isn’t python where index matters
idk

I think you could refer to colbert’s earlier post if you haven’t done so already for this question (If I hopefully don’t get mis-corrected):

For the differences of end) & end, have you considered doing quick research?

end) is used to close a statement where a function is used, e.g

pcall(function()

end) -- pcall takes a function argument and is closed by the )
function() 

end -- <- no ) because you are not closing anything


--if it helps, the pcall statement is equal to
pcall(function() end)
2 Likes

Colbert’s post explains 1 thing, why you can’t have multiple ends.

technically you have cases where you could have end))

if you have a ( you need to close it off with )
so ye

My post isn’t a good reference for this thread since it tackles a different issue but I guess some of the wording is applicable in the sense of what an end is. That being said, there’s no difference between either. The closing parenthesis is put there in order to close an open one. Parenthesis need to match: if you have an open one you also need a closed one.

2 Likes

I’ve done this post as the end error that I’ve got struck me, why do we need an end?

so the compiler knows when to end the function statement, it’s equal to javascript’s {}

Probably to close the function. yk it’s pretty important.

End declares the end of a scope. Anything you open must be matched with a closer. end closes a scope. A closed parenthesis closes an open parenthesis. It’s all about matching. Other languages have this as well but some may not feature an explicit keyword for it.

end is to close statements,
and end) is the same the braquet is just here to close another one

I still don’t get the difference between end and end)…

there isn’t a difference

the ) is there to close the (
its simple

So now I’m starting to get it. A function needs to be closed while an if statement does not need to be closed.

exactly because the if statement never called a ( at all
:smiley:

I’ll try to mark all of you as solutions at the same time :laughing:

Welp, you can only do one person.

You could refer to the Functions reference inside the Lua website for a more detailed explanation:

https://www.lua.org/pil/5.html

you could mark yourself as the solution