Page 1 of 1

Error when running my game

Posted: Wed Feb 09, 2022 7:30 pm
by Seth144k
Whenever i run my game it says that its comparing a value with nil which doesnt make any sense. i even changed the value to 1 to see if that worked and it didnt! i have provided the .love for you all to see the source code

Re: Error when running my game

Posted: Wed Feb 09, 2022 7:32 pm
by Seth144k
So whenever I run my love game it says that it was comparing a value with nil (its on cookie.lua line 26) im not really understanding why..?
i even tried changing the value to 1 or something higher and its still giving the same error so im not really sure what to do. anyone who sees this please help!

Re: Error when running my game

Posted: Wed Feb 09, 2022 7:33 pm
by Seth144k
So whenever I run my love game it says that it was comparing a value with nil (its on cookie.lua line 26) im not really understanding why..?
i even tried changing the value to 1 or something higher and its still giving the same error so im not really sure what to do. anyone who sees this please help!

Re: Error when running my game

Posted: Wed Feb 09, 2022 7:34 pm
by Seth144k
oh im sorry i thought i posted wrong... please dont take down my post for spam as i sincerely got confused

Re: Error when running my game

Posted: Wed Feb 09, 2022 8:33 pm
by dusoft
I think your .love is incorrectly packed:

[love "boot.lua"]:321: No code to run
Your game might be packaged incorrectly.
Make sure main.lua is at the top level of the zip.

Re: Error when running my game

Posted: Wed Feb 09, 2022 9:10 pm
by Seth144k
how do you pack it correctly then?

Re: Error when running my game

Posted: Wed Feb 09, 2022 9:19 pm
by darkfrei
Seth144k wrote: Wed Feb 09, 2022 9:10 pm how do you pack it correctly then?
zip:
  • main.lua
  • all your other files
  • all your folders with subfolders

Re: Error when running my game

Posted: Thu Feb 10, 2022 12:37 am
by pgimeno
Basically what darkfrei is saying is that you should not zip the folder, because then main.lua is not in the top level, but in a folder, and then it doesn't work.

Anyway, the error you're getting makes perfect sense, because the following code is executed BEFORE cookie:load():

Code: Select all

if cookie.clicks >= 5 then
    print("boi!")
end
Basically, when you load a file, Lua runs everything in that file. If there are function definitions, the effect of running them is to define the functions. And when it has all the functions defined, then it runs "if cookie.clicks >= 5 then", and it notices that cookie.clicks does not have any value (because cookie:load() is defined, but it hasn't run yet!) and that means that cookie.clicks is nil, which you try to compare with 5, and crashes.

Maybe you meant that to be inside cookie:mousepressed(), or somewhere else, so that it is executed after cookie:load().

Then you have another problem in distance.lua; the argument order is wrong. You have distanceBetween(x1, x2, y1, y2) but it should be distanceBetween(x1, y1, x2, y2). Or you could call it with the arguments in the specified order, first all X and then all Y, but that's not very conventional.