Sublime Forum

"Function" command not working

#1

So I am brand new to coding and I was following a Lua tutorial recently. He began to use the function command and I copied his line code exactly like he did and yet and error keeps occurring. Hopefully someone will be able to help thanks!

0 Likes

#2

Your end is indented to far.

0 Likes

#3

I just tried it and it still does not work. Also there is still a red ring around the function command and it says “matching bracket could not be found” I wish I wasn’t so new to coding!

0 Likes

#4

Functions in lua (and also conditional statements) end with the end keyword, but you don’t have one. That’s why the error is at the bottom of the file and telling you that it expected to see an end to close the function, but instead it found the end of the file.

function Factorial(number)
    if number == 0 then
        return 1
    else
        return number * Factorial(number - 1)
    end
end

print(Factorial(5))
2 Likes

#5

That worked! Thank you so much for your help.

0 Likes