Play in Löve does not work after compiling

Asked

Viewed 190 times

5

I recently created a game based on löve, that once finished and tested, I decided to try to compile.

I followed the tutorial compilation of the löve wiki, using:

copy /b love.exe+GhostShield.love GhostShield.exe

He compiled normally, but when I ran the compiled game, I came up with an unexpected problem:

Error

controllers/menuController.lua:8: Attempt to compare number with nil

Traceback

controllers/menuController.lua:8: in Function 'menuDisplay'
main.lua:180: in Function 'draw'
[C]: in Function 'xpcall'

I looked for the line 8 that failed:

menu.menuPresentation()
menu.menuButton(200,250,90,30,"Jogar")
menu.menuButton(500,250,90,30,"Como jogar")
if  ranking.readRanking() >= 200 then --Problema aqui
    menu.menuButton(350,350,90,30,"Extra")
end
menu.menuButton(350,500,90,30,"Sair")

And the function that it retrieves the value of the ranking:

ranking.readRanking = function ()
    rankingReader = love.filesystem.read(rankingLocal, love.filesystem.getSize(rankingLocal))
    return tonumber(rankingReader)  
end

The curious thing is that I can drag the folder to the löve icon or compress it into . zip and change the extension to . love, and it works perfectly, the error only occurs when I compile into executable.

Annotation: There is a function to change the shape of the mouse at the beginning of the code, and the mouse changes correctly, even after the error, so I believe it has been compiled correctly.

When the program starts, I do a check on it:

if not love.filesystem.exists(rankingLocal) then
    ranking.createRanking()
end

Theoretically, by doing so, I guarantee that the file exists, even if the default folder changes:

ranking.createRanking = function ()
    rankCreate = love.filesystem.newFile(rankingLocal)
    rankCreate:open("w")
    rankCreate:write("0000")
    rankCreate:close()
end

One detail that I found interesting is that if I run the my game as "independent program", it fails, but if drag it to run on the basis of löve2d, dragging it to it, works without any problem, both in the version installed on the system and in the zipped version...

  • 1

    What is the value of rankingLocal? It seems that in the place where you run after compiling it cannot find rankingLocal and ends up returning nil.

  • 1

    @brasofilo: besides making it easier for those who want to reproduce the problem, not having to manually copy the text of the image.

  • @Lucasnunes In the case, rankingLocal is set to "ranking.txt", and in case I still put a test to confirm that the file exists, and added a value manually to test. The curious thing is that if I don’t change anything, and run as a project, it works smoothly.

  • @brasofilo I will put the lines with problems

  • @Gammeth Another explanation would be that when compiled, the executable uses another default directory, different from the one where . exe is. So "ranking.txt" is not found. You could share the compiled version (if possible), to verify this.

  • I don’t know if you have it in Löve, but if you do require('lfs'), you can see which is the current directory of the executable with print(lfs.currentdir());. From there you can compare the before and after compiling.

  • @Lucasnunes I do not know if it is possible to require the extensions of the moon, because I once tried to recover the iup and failed everything I tried.

  • When I run here it works normal. I really think the problem is with setting the default program directory. But, I could not test.

  • @Lucasnunes you could confirm that the game created the file ranking.txt in %appdata%/LOVE/Ghost Shield?

  • I think I managed to fix it. But the file was created in %appdata%/Ghost Shield/.

Show 5 more comments

1 answer

2


From the looks of it, löve just write in the directory %appdata% (in the case of Windows), as in wiki, where you can create a folder for your project.

Then, after compiling, the löve apparently no longer accepts the default folder %appdata%/LOVE/, requiring you to create your own folder for your project.

To resolve this, in love.load() add the following call:

 love.filesystem.setIdentity("Ghost Shield")

This function will define which files your project creates will be written in %appdata%/Ghost Shield/.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.