Search code examples
lua

'<eof>' line 20 expected near 'function'


There Was A Error On My Lua Script And You Can See It By Yourself So Here Are The Script

function opponentNoteHit()
    health = getProperty('health')
    if getProperty('health') > 0.05 then
        setProperty('health', health- 0.02);
    end
end
    
function onCreate()

    --Adds Lua Sprites
    addCharacterToList('yotsugameoverscreen', 'boyfriend');

   makeAnimatedLuaSprite('yotsugameoverscreen', 'yotsugameoverscreen');
    luaSpriteAddAnimationByPrefix('yotsugameoverscreen', 'missyotright', 'miss_yot_right', 24, false)
    luaSpriteAddAnimationByPrefix('yotsugameoverscreen', 'missyotright', 'miss_yot_right', 24, true)
    luaSpriteAddAnimationByPrefix('yotsugameoverscreen', 'yotidle', 'yot_idle', 24, false)
         end
return Function_Continue

function onCreate()
    setPropertyFromClass('GameOverSubstate','characterName', 'yotsugameoverscreen'); --Character json file for the death animation
end

and the error is '' line 20 expected near 'function'


Solution

  • return is the last statement in a block of code. You cannot define a function after it as in

    return Function_Continue
    
    function onCreate()
        setPropertyFromClass('GameOverSubstate','characterName', 'yotsugameoverscreen'); --Character json file for the death animation
    end
    

    If you want to skip the function definiton you can do

    do return Function_Continue end
    

    I don't know what you are trying to do, but the only other two options are to move return Function_Continue to the end of the file or into one of those functions.

    Maybe you just have the end in the wrong line?