Log In  

whenever i make a function, such as the one below, and try to run it, pico-8 almost always returns a syntax error, saying something along the lines of "<EOF> EXPECTED AT LINE 23", where line 23 is the last line of the last function in the code.
below shows the framework of the functions i usually code, "blah" obviously being substituted with code.

FUNCTION DOSTUFF()
IF BLAH THEN
BLAH BLAH BLAH
BLAH BLAH BLAH --this line is where an "<eof>" is usually expected
END
END
P#32713 2016-11-23 10:53 ( Edited 2016-11-23 23:45)

It sounds like most of the time you're managing to forget the "then" on your IF BLAH THEN line; an if without a then is treated as a one-liner that in turn requires (and allows) no corresponding END statement.

So, for example, this as the sole content of a program runs fine (and does nothing interesting):

function dostuff()
  if true then
    local x = 0
    x += 1
  end
end

Whereas this, without that "then", barfs up the EOF warning you're mentioning:

function dostuff()
  if true
    local x = 0
    x += 1
  end
end
P#32716 2016-11-23 12:50 ( Edited 2016-11-23 17:50)

@joshmillard: I, too, am guilty of forgetting thens and dos but I'm soon reminded. your last example brings up " 'then' expected near 'local' "

@badatcoding: could you provide a copy/paste example? tried a few things but never got that error.

edit:
@joshmillard:
this one though:

function dostuff()
 if (true) x = 0
    y=2
 end
end

Syntax error line 3
y=2
<EOF> expected near 'END'

should be line 4/5 or "unexpected 'END'" on line 5 I guess...
well I'm often puzzled by error messages in pico8, I think I mostly read 'problem around there' (might be only related to lua though, I don't use it anywhere else so I wouldn't know)

P#32718 2016-11-23 14:52 ( Edited 2016-11-23 23:09)

Yeah, the error reporting on these could be clearer -- an "unexpected END on line x" message would be more communicative than just barfing about EOF more generally -- though that's easy for me to say as someone who has never had to implement such a thing. I don't know how much of what exists is native Lua reporting being passed through vs. zep bootstrapping his own error system.

P#32720 2016-11-23 18:45 ( Edited 2016-11-23 23:45)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-06-02 12:17 | 0.021s | 4194k | Q:19