a few months ago i decided to learn this game engine, and now i am sticking with it, so i decided to make a project with it
but i came across an error:
Error
Syntax error: main.lua 'end' expected (to close 'function' at line 273) near '<eof>'
Traceback
[C]: at 0x7ffd68d228f0
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
i made sure everything was okay about each end, but then found it was all completely normal. i wondered if i had exceeded some sort of limit for lines...
file : https://mega.nz/file/SAZFVIQK#IEJO3h-5I ... 7n41Mjk5ro
error i encountered while working on a project (solved)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
error i encountered while working on a project (solved)
Last edited by kappaster on Wed Feb 02, 2022 11:02 pm, edited 1 time in total.
Re: error i encountered while working on a project
Your love.update function starts at line 273, it doesnt have an end
that 'end' ought to be somewhere on line 2200
the error message says this too, and an editor with some auto-indent capabilities might help with this issue, another thing , after decade of programming I like the directness of just writing code that does the job without worrying too much about extracting functions etc, but your code would be a lot easier to reason about if you instead of duplicating the same blocks over and over would use a little function and a for loop occasionally .
that 'end' ought to be somewhere on line 2200
the error message says this too, and an editor with some auto-indent capabilities might help with this issue, another thing , after decade of programming I like the directness of just writing code that does the job without worrying too much about extracting functions etc, but your code would be a lot easier to reason about if you instead of duplicating the same blocks over and over would use a little function and a for loop occasionally .
Re: error i encountered while working on a project
debugging is a process of elimination; syntax errors are the easiest because the compiler actually finds the error for you. in this case, the function love.update is missing a closing 'end' statement. the reason you can't figure out what is wrong is because love.update is ~2k lines of if then clauses(!) the first one (the one beginning with " if love.keyboard.isDown("return") " is the size of the whole function. this is most easily seen using an editor that supports folding nested statements. break the function down into smaller parts to isolate the issue. maybe make a different function for each scene, and use a state machine to move through them.
e.g.
e.g.
Code: Select all
scenes = {}
currentscene = 1
local function scene1(...)
-- do whatever
end
scenes.scene1 = scene1
-- add rest of scene functions to table of scenes
function love.update(dt)
scenes['scene'..tostring(currentscene)]() -- update the current scene
end
- EngineerSmith
- Prole
- Posts: 38
- Joined: Thu Dec 02, 2021 11:38 am
- Contact:
Re: error i encountered while working on a project
That's a big update loop. You should check out ways to split your code into multiple files so you don't end up with a blob file like this and it's much more manageable/maintainable.
There's an end missing on Ln375
There's an end missing on Ln375
Re: error i encountered while working on a project
spoiler alert!
Re: error i encountered while working on a project
yal2du wrote: ↑Wed Feb 02, 2022 12:32 pm debugging is a process of elimination; syntax errors are the easiest because the compiler actually finds the error for you. in this case, the function love.update is missing a closing 'end' statement. the reason you can't figure out what is wrong is because love.update is ~2k lines of if then clauses(!) the first one (the one beginning with " if love.keyboard.isDown("return") " is the size of the whole function. this is most easily seen using an editor that supports folding nested statements. break the function down into smaller parts to isolate the issue. maybe make a different function for each scene, and use a state machine to move through them.
e.g.
Code: Select all
scenes = {} currentscene = 1 local function scene1(...) -- do whatever end scenes.scene1 = scene1 -- add rest of scene functions to table of scenes function love.update(dt) scenes['scene'..tostring(currentscene)]() -- update the current scene end
thanks for the advice. might try it for future things
Re: error i encountered while working on a project
also finally realizing where the end was made me feel like i was blind, but no worriesEngineerSmith wrote: ↑Wed Feb 02, 2022 12:35 pm That's a big update loop. You should check out ways to split your code into multiple files so you don't end up with a blob file like this and it's much more manageable/maintainable.
There's an end missing on Ln375
thanks
Re: error i encountered while working on a project (solved)
I've written a program to easily detect these kinds of problems:
https://codeberg.org/pgimeno/Gists/src/ ... nt-checker
When applied to this file it says this:
All errors past the first are a consequence of that one, so fixing the first one makes it pass.
https://codeberg.org/pgimeno/Gists/src/ ... nt-checker
When applied to this file it says this:
Code: Select all
$ lua indentchecker.lua big.lua
**** big.lua
Warning at line 376: Misindented elseif (if)
Warning at line 463: Misindented elseif (if)
Warning at line 480: Misindented end (if)
Warning at line 2199: Misindented end (if)
Warning at line 2221: Unexpected EOF looking for block terminator
Re: error i encountered while working on a project (solved)
Any decent editor will report this without need to run another script. But that's useful for people who just use some basic notepad or such.pgimeno wrote: ↑Fri Feb 04, 2022 5:48 pm I've written a program to easily detect these kinds of problems:
https://codeberg.org/pgimeno/Gists/src/ ... nt-checker
When applied to this file it says this:All errors past the first are a consequence of that one, so fixing the first one makes it pass.Code: Select all
$ lua indentchecker.lua big.lua **** big.lua Warning at line 376: Misindented elseif (if) Warning at line 463: Misindented elseif (if) Warning at line 480: Misindented end (if) Warning at line 2199: Misindented end (if) Warning at line 2221: Unexpected EOF looking for block terminator
I recommend Sublime and Atom editors. Both feature syntax highlighting for Lua and there are packages specifically made for LOVE including function hinting and autocomplete.
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Who is online
Users browsing this forum: Google [Bot], Semrush [Bot] and 4 guests