Error when running my game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Seth144k
Prole
Posts: 29
Joined: Wed Jan 19, 2022 8:45 pm

Error when running my game

Post 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
Attachments
CodeClicker.love (2).love
(1.1 KiB) Downloaded 126 times
Seth144k
Prole
Posts: 29
Joined: Wed Jan 19, 2022 8:45 pm

Re: Error when running my game

Post 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!
Seth144k
Prole
Posts: 29
Joined: Wed Jan 19, 2022 8:45 pm

Re: Error when running my game

Post 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!
Seth144k
Prole
Posts: 29
Joined: Wed Jan 19, 2022 8:45 pm

Re: Error when running my game

Post by Seth144k »

oh im sorry i thought i posted wrong... please dont take down my post for spam as i sincerely got confused
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Error when running my game

Post 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.
Seth144k
Prole
Posts: 29
Joined: Wed Jan 19, 2022 8:45 pm

Re: Error when running my game

Post by Seth144k »

how do you pack it correctly then?
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Error when running my game

Post 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
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Error when running my game

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 13 guests