Page 1 of 1

First try won't load. ERROR= love.load function is nil

Posted: Wed Sep 24, 2014 8:48 pm
by meat_sim
Hello! Brand new to this...obviously.
I cannot get anything to run. I followed a Youtube tutorial just to get the hang of things,
but when I tried to run it, the Love screen gives me errors. I searched all over for the
answer to no avail.

Answers to questions I assume you will ask:
--I downloaded both love and lua 64 versions.
--main.lua is at the root of my folder
--I zipped the folder and changed the extension to .love
--All the .lua files are just that (not .lua.text)
--I have tried double-clicking the .love file and tried dragging it to love.exe

I have the code down exactly as in the tutorial, it's just a blue square!
I'll just post it below.
Please let me know anything that might help.

Spanks!

MAIN.LUA

Code: Select all

require "player"

function love.load()
	love.graphics.setBackgroundColor(255,255,255)

	groundlevel = 400

	--loading classes
	player.load()
end

function love.update(dt)
	UPDATE_PLAYER(dt)
end
function love.draw()
	DRAW_PLAYER()
end
CONF.LUA

Code: Select all

function love.conf(t)
	t.title = "Platform"
	t.screen.width = 1200
	t.screen.height = 750
end
PLAYER.LUA

Code: Select all

player = {}

function player.load()
	player.x = 10
	player.y = 10
	player.xvel = 0
	player.yvel = 0
	player.friction = 6
	player.speed = 2200
	player.width = 50
	player.height = 50
end

function player.draw()
	love.graphics.setColor(0,0,255)
	love.graphics.rectangle("fill",player.x,player.y,player.width,player.height)
end

function player.physics(dt)
	player.x = player.x * player.xvel * dt
	player.y = player.y * player.yvel * dt
	player.xvel = player.xvel * (1 - math.min(dt*player.friction, 1))
end

function player.move(dt)
	if love.keyboard.isDown('right') and
	player.xvel < player.speed then
		player.xvel = player.xvel + player.speed * dt
	end
	if love.keyboard.isDown('left') and
	player.xvel > -player.speed then
		player.xvel = player.xvel - player.speed * dt
	end

end

function player.boundary()
	if player.x < 0 then
		player.x = 0
		player.xvel = 0
	end
	if player.y + player.height > groundlevel then
		player.y = groundlevel - player.height
		player.yvel = 0
	end
end


function UPDATE_PLAYER(dt)
	player.physics(dt)
	player.move(dt)
	player.boundary()
end

function DRAW_PLAYER()
	player.draw()
end

Re: First try won't load. ERROR= love.load function is nil

Posted: Wed Sep 24, 2014 8:55 pm
by Zilarrezko
Hmmm. Try uploading the .love you made. In the upload attachment in the bottom when you reply.

The code looks fine at a first glance, so it might be something else. But I'll double check after posting this.

EDIT: Conf.lua may have some mistakes. (I'm not familiar with past versions of löve).

but..

Code: Select all

function love.conf(t)
   t.title = "Platform"
   t.screen.width = 1200
   t.screen.height = 750
end
Should be...

Code: Select all

function love.conf(t)
   t.window.title = "Platform"
   t.window.width = 1200
   t.window.height = 750
end
Other than that... The code looks fine.

Re: First try won't load. ERROR= love.load function is nil

Posted: Wed Sep 24, 2014 9:31 pm
by meat_sim
I just tried switching the conf.lua to what you said, but it didn't change the outcome.

Here's the .love file.

.....It still says .zip
Am i doing something wrong there?

Re: First try won't load. ERROR= love.load function is nil

Posted: Wed Sep 24, 2014 9:59 pm
by Robin
You packaged your game incorrectly (main.lua wasn't at the top level). When I unzipped your game and tried it, it worked (although Zilarrezko was right about your conf.lua).

Re: First try won't load. ERROR= love.load function is nil

Posted: Wed Sep 24, 2014 10:09 pm
by artofwork
The problem is any number times 0 always equals 0

Code: Select all

function player.physics(dt)
   player.x = player.x * player.xvel * dt
   player.y = player.y * player.yvel * dt
   player.xvel = player.xvel * (1 - math.min(dt*player.friction, 1))
end
The value passed to player.physics is less then 0, its roughly 0.12, which fluctuates up and down

Regardless of what player.x, player.y, player.xvel or player.yvel, player.x and player.y will always be equal to 0 which keeps you stationary

Now if you change the multiplication from

Code: Select all

function player.physics(dt)
   player.x = player.x * player.xvel * dt
   player.y = player.y * player.yvel * dt
   player.xvel = player.xvel * (1 - math.min(dt*player.friction, 1))
end
to

Code: Select all

function player.physics(dt)
   player.x = player.x * player.xvel + dt
   player.y = player.y * player.yvel + dt
   player.xvel = player.xvel * (1 - math.min(dt+player.friction, 1))
end
and

Code: Select all

function player.move(dt)
   if love.keyboard.isDown('right') and
  player.xvel < player.speed then
      player.xvel = player.xvel + player.speed * dt
   end
   if love.keyboard.isDown('left') and
   player.xvel > -player.speed then
      player.xvel = player.xvel - player.speed * dt
   end

end
to

Code: Select all

function player.move(dt)
   if love.keyboard.isDown('right') and
  player.xvel < player.speed then
      player.xvel = player.xvel + player.speed + dt
   end
   if love.keyboard.isDown('left') and
   player.xvel > -player.speed then
      player.xvel = player.xvel - player.speed + dt
   end

end
You will be able to move your box, however you won't get far because the code needs work & to be truthful its overkill

Anyhow I added somethings to help you test your code in player.lua and fix whatever bugs, I could re-write this but then what would you learn from that?

Code: Select all

player = {}
d = 0
x = 0
y = 0
vx = 0
vy = 0
function player.load()
   player.x = 10
   player.y = 10
   player.xvel = 0
   player.yvel = 0
   player.friction = 6
   player.speed = 2200
   player.width = 50
   player.height = 50
end

function player.draw()
   love.graphics.setColor(0,0,255)
   love.graphics.rectangle("fill",player.x,player.y,player.width,player.height)
end

function player.physics(dt)
   player.x = player.x * player.xvel + dt
   x = player.x
   player.y = player.y * player.yvel + dt
   y = player.y
   player.xvel = player.xvel * (1 - math.min(dt+player.friction, 1))
end

function player.move(dt)
   if love.keyboard.isDown('right') and
  player.xvel < player.speed then
      player.xvel = player.xvel + player.speed + dt
	  vx = player.xvel
   end
   if love.keyboard.isDown('left') and
   player.xvel > -player.speed then
      player.xvel = player.xvel - player.speed + dt
	  vy = player.xvel
   end

end

function player.boundary()
   if player.x < 0 then
      player.x = 0
      player.xvel = 0
   end
   if player.y + player.height > groundlevel then
      player.y = groundlevel - player.height
      player.yvel = 0
   end
end


function UPDATE_PLAYER(dt)
   player.physics(dt)
   d = dt
   player.move(dt)
   player.boundary()
end

function DRAW_PLAYER()
prints("dt "..d, 0, 100)
prints("player.x "..x, 0, 150)
prints("player.y "..y, 0, 200)
prints("player.xvel + "..vx, 0, 250)
prints("player.xvel - "..vy, 0, 300)
   player.draw()
end

function prints(v, x, y)
	love.graphics.print(v, x, y)
end

Re: First try won't load. ERROR= love.load function is nil

Posted: Wed Sep 24, 2014 10:25 pm
by Zilarrezko
Yeah, to elaborate on robin. You have to zip up the Files, not the folder containing the files.

I made a video of how to do this! :awesome:


Re: First try won't load. ERROR= love.load function is nil

Posted: Wed Sep 24, 2014 11:24 pm
by meat_sim
Yay! It loads. That was the step that was important.
Fiddling with everything inside is next!
Thanks everybody

Re: First try won't load. ERROR= love.load function is nil

Posted: Thu Sep 25, 2014 12:04 am
by Zilarrezko
meat_sim wrote:Yay! It loads. That was the step that was important.
Fiddling with everything inside is next!
Thanks everybody
Happy to help man, Have a good one.

Re: First try won't load. ERROR= love.load function is nil

Posted: Thu Sep 25, 2014 5:08 am
by ivan
artofwork wrote:Now if you change the multiplication from

Code: Select all

function player.physics(dt)
   player.x = player.x * player.xvel * dt
   player.y = player.y * player.yvel * dt
   player.xvel = player.xvel * (1 - math.min(dt*player.friction, 1))
end
to

Code: Select all

function player.physics(dt)
   player.x = player.x * player.xvel + dt
   player.y = player.y * player.yvel + dt
   player.xvel = player.xvel * (1 - math.min(dt+player.friction, 1))
end
I believe it should be:

Code: Select all

function player.physics(dt)
   player.x = player.x + player.xvel * dt
   player.y = player.y + player.yvel * dt
   player.xvel = player.xvel * (1 - math.min(dt+player.friction, 1))
end
The variable "friction" is technically called "damping" (or "linear damping" in this case) and is calculated like so:

Code: Select all

local damp = 1 - d.damping*dt
if damp < 0 then damp = 0 end
if damp > 1 then damp = 1 end
-- usually applied to both x and y, I guess for platformers you're good with just "xvel"
player.xvel = player.xvel * damp
player.yvel = player.yvel * damp

Code: Select all

function player.move(dt)
   if love.keyboard.isDown('right') and
  player.xvel < player.speed then
      player.xvel = player.xvel + player.speed * dt
   end
   if love.keyboard.isDown('left') and
   player.xvel > -player.speed then
      player.xvel = player.xvel - player.speed * dt
   end

end
This looks correct if you assume that "player.speed" is actually the player's acceleration.