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...
What is the value of
rankingLocal
? It seems that in the place where you run after compiling it cannot findrankingLocal
and ends up returning nil.– Lucas Lima
@brasofilo: besides making it easier for those who want to reproduce the problem, not having to manually copy the text of the image.
– Miguel Angelo
@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.– Gammeth
@brasofilo I will put the lines with problems
– Gammeth
@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.
– Lucas Lima
I don’t know if you have it in
Löve
, but if you dorequire('lfs')
, you can see which is the current directory of the executable withprint(lfs.currentdir());
. From there you can compare the before and after compiling.– Lucas Lima
@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.
– Gammeth
When I run here it works normal. I really think the problem is with setting the default program directory. But, I could not test.
– Lucas Lima
@Lucasnunes you could confirm that the game created the file
ranking.txt
in%appdata%/LOVE/Ghost Shield
?– Gammeth
I think I managed to fix it. But the file was created in
%appdata%/Ghost Shield/
.– Lucas Lima