What are 'nil' errors?

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.
User avatar
Mogex
Prole
Posts: 15
Joined: Thu Dec 06, 2012 2:13 am

What are 'nil' errors?

Post by Mogex »

And how do they happen?

I have this error CONSTANTLY and I'm really getting sick of it.
atVUh.png
atVUh.png (22.68 KiB) Viewed 379 times

Code: Select all

function love.load()
 love.physics.setMeter(60)
 world = love.physics.newWorld(0, 9.81*64, true)
 
 --image = love.graphics.newImage("sheet1.png")
 --x = 50
 --y = 50
 --speed = 100
 
 player = {}
 player.image = love.graphics.newImage("sheet1.png")
 player.left1 = love.graphics.newQuad(10, 30, 91, 170, 550, 170) --(10, 30, 91, 170, 550, 170)
 

 objects = {} --Creates table "objects"
  
  --The ground
  objects.ground = {}
  objects.ground.body = love.physics.newBody(world, 650/2, 650-50/2) --2nd & 3rd parameter are used to anchor object.ground to fit in correct place
  objects.ground.shape = love.physics.newRectangleShape(650, 50) --Width = 650, Height = 50
  objects.ground.fixture = love.physics.newFixture(objects.ground.body, objects.ground.shape) --attach shape to body
  
  --Ball
  objects.ball = {}
  objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic") -- Centering of the ball, made to be dynamic to move.
  objects.ball.shape = love.physics.newCircleShape(20) -- Radius = 20
  objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape, 1)
  objects.ball.fixture:setRestitution(0.9) --Adds le bounce
  
  --Blocks
  objects.block1 = {}
  objects.block1.body = love.physics.newBody(world, 200, 550, "dynamic")
  objects.block1.shape = love.physics.newRectangleShape(0, 0, 50, 100)
  objects.block1.fixture = love.physics.newFixture(objects.block1.body, objects.block1.shape, 5)
  
  objects.block2 = {}
  objects.block2.body = love.physics.newBody(world, 200, 400, "dynamic")
  objects.block2.shape = love.physics.newRectangleShape(0, 0, 100, 50)
  objects.block2.fixture = love.physics.newFixture(objects.block2.body, objects.block2.shape, 2)
  
  objects.player = {}
  objects.player.body = love.physics.newBody(world, 10, 30, "dynamic")
  objects.player.shape = love.physics newRectangleShape(10, 30, 91, 170)
  objects.player.fixture = love.physics.newFixture(objects.player.body, objects.player.shape)
  
  love.graphics.setBackgroundColor(101, 64, 251) --Blue background!
  love.graphics.setMode(650, 650, false, true, 0) --set the window dimensions to 650 by 650 with no fullscreen, vsync on, and no antialiasing
end

function love.update(dt)
world:update(dt) --this puts the world into motion
 
 if love.keyboard.isDown("right") then --press the right arrow key to push the ball to the right
    objects.ball.body:applyForce(400, 0)
  elseif love.keyboard.isDown("left") then --press the left arrow key to push the ball to the left
    objects.ball.body:applyForce(-400, 0)
  elseif love.keyboard.isDown("up") then --press the up arrow key to set the ball in the air
    objects.ball.body:setPosition(650/2, 650/2)
  end
end

function love.draw()

love.graphics.setCaption("Mars")
 --love.graphics.draw(image, sheet1.png, 50, 50)
 
 love.graphics.drawq(player.image, player.left1, 100, 100)
 
 love.graphics.setColor(72, 160, 14) -- set the drawing color to green for the ground
 love.graphics.polygon("fill", objects.ground.body:getWorldPoints(objects.ground.shape:getPoints())) -- draw a "filled in" polygon using the ground's coordinates
 
 love.graphics.setColor(193, 47, 14) --set the drawing color to red for the ball
 love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())
 
 love.graphics.setColor(50, 50, 50) -- set the drawing color to grey for the blocks
 love.graphics.polygon("fill", objects.block1.body:getWorldPoints(objects.block1.shape:getPoints()))
 love.graphics.polygon("fill", objects.block2.body:getWorldPoints(objects.block2.shape:getPoints()))
 
 end
Last edited by Mogex on Sat Dec 22, 2012 8:54 pm, edited 1 time in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: What are 'nil' errors?

Post by Nixola »

It seems that newRectangleShape doesn't exist in the table you're searching it, could you upload a .love?

EDIT: You posted your code... Look line 43:

Code: Select all

objects.player.shape = love.physics newRectangleShape(10, 30, 91, 170)
You typed a space instead of a dot
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Mogex
Prole
Posts: 15
Joined: Thu Dec 06, 2012 2:13 am

Re: What are 'nil' errors?

Post by Mogex »

Nixola wrote:It seems that newRectangleShape doesn't exist in the table you're searching it, could you upload a .love?

EDIT: You posted your code... Look line 43:

Code: Select all

objects.player.shape = love.physics newRectangleShape(10, 30, 91, 170)
You typed a space instead of a dot
*facepalm*

and thanks.. ugh lol.
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: What are 'nil' errors?

Post by substitute541 »

Nil means nothing.

Nil errors means that the var/function that your using does not exist.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
Mogex
Prole
Posts: 15
Joined: Thu Dec 06, 2012 2:13 am

Re: What are 'nil' errors?

Post by Mogex »

Gah, I have another issue I'm trying to get around, and I've tried every logical solution I know of, this is the issue:
v1bN6.png
v1bN6.png (75.84 KiB) Viewed 377 times

Code: Select all

function love.load()
 love.physics.setMeter(60)
 world = love.physics.newWorld(0, 9.81*64, true)
 
 --image = love.graphics.newImage("sheet1.png")
 --x = 50
 --y = 50
 --speed = 100
 
 player = {}
 player.characters = love.graphics.newImage("characters.png")
 player.left1 = love.graphics.newQuad(10, 30, 91, 170, 550, 170) --(10, 30, 91, 170, 550, 170)
 love.graphics.newImage("characters.png")

 objects = {} --Creates table "objects" sheet1.png
  
  --The ground
  objects.ground = {}
  objects.ground.body = love.physics.newBody(world, 650/2, 650-50/2) --2nd & 3rd parameter are used to anchor object.ground to fit in correct place
  objects.ground.shape = love.physics.newRectangleShape(650, 50) --Width = 650, Height = 50
  objects.ground.fixture = love.physics.newFixture(objects.ground.body, objects.ground.shape) --attach shape to body
  
  --Ball
  objects.ball = {}
  objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic") -- Centering of the ball, made to be dynamic to move.
  objects.ball.shape = love.physics.newCircleShape(20) -- Radius = 20
  objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape, 1)
  objects.ball.fixture:setRestitution(0.85) --Adds le bounce - 0.9
  
  --Blocks
  objects.block1 = {}
  objects.block1.body = love.physics.newBody(world, 200, 550, "dynamic")
  objects.block1.shape = love.physics.newRectangleShape(0, 0, 50, 100)
  objects.block1.fixture = love.physics.newFixture(objects.block1.body, objects.block1.shape, 5)
  
  objects.block2 = {}
  objects.block2.body = love.physics.newBody(world, 200, 400, "dynamic")
  objects.block2.shape = love.physics.newRectangleShape(0, 0, 100, 50)
  objects.block2.fixture = love.physics.newFixture(objects.block2.body, objects.block2.shape, 2)
  
  objects.player = {}
  objects.player.body = love.physics.newBody(world, 10, 30, "dynamic")
  objects.player.shape = love.physics.newRectangleShape(10, 30, 91, 170)
  objects.player.fixture = love.physics.newFixture(objects.player.body, objects.player.shape)
  
  love.graphics.setBackgroundColor(101, 64, 251) --Blue background!
  love.graphics.setMode(650, 650, false, true, 0) --set the window dimensions to 650 by 650 with no fullscreen, vsync on, and no antialiasing
end

function love.update(dt)
world:update(dt) --this puts the world into motion
 
 if love.keyboard.isDown("right") then --press the right arrow key to push the ball to the right
    objects.ball.body:applyForce(400, 0)
  elseif love.keyboard.isDown("left") then --press the left arrow key to push the ball to the left
    objects.ball.body:applyForce(-400, 0)
  elseif love.keyboard.isDown("up") then --press the up arrow key to set the ball in the air
    objects.ball.body:setPosition(650/2, 650/2)
  end
end

function love.draw()

 love.graphics.setCaption("Soldiers: Anarchy of Oaths")
 love.graphics.drawq(characters.png, 50, 50)
 
 love.graphics.drawq(player.image, player.left1, 100, 100)
 love.graphics.polygon("fill", objects.player.body:getWorldPoints(objects.player.shape:getPoints()))
 
 love.graphics.setColor(72, 160, 14) -- set the drawing color to green for the ground
 love.graphics.polygon("fill", objects.ground.body:getWorldPoints(objects.ground.shape:getPoints())) -- draw a "filled in" polygon using the ground's coordinates
 
 love.graphics.setColor(193, 47, 14) --set the drawing color to red for the ball
 love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())
 
 love.graphics.setColor(255, 255, 255) -- set the drawing color to white for the blocks
 love.graphics.polygon("fill", objects.block1.body:getWorldPoints(objects.block1.shape:getPoints()))
 love.graphics.polygon("fill", objects.block2.body:getWorldPoints(objects.block2.shape:getPoints()))
 
 end
I've tried looking for grammatical errors in the declaration of 'characters.png', tried putting it on a table, but it never seems to find it.

I would like to know how to fix this and what the term 'global' really means if it doesn't mean the love.load function.
User avatar
Mogex
Prole
Posts: 15
Joined: Thu Dec 06, 2012 2:13 am

Re: What are 'nil' errors?

Post by Mogex »

Bump!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
User avatar
TheDeskPop
Prole
Posts: 10
Joined: Fri Dec 28, 2012 6:23 pm
Contact:

Re: What are 'nil' errors?

Post by TheDeskPop »

A couple things... Your love.draw is the problem. You have love.graphics.drawq -- Also love.graphics.draw(characters.png, 50, 50) will not work it should look like this:

At line 64 in the code it tells you that 'characters' is a nil value. You need to edit it to this:

Code: Select all

function love.draw()

   love.graphics.setCaption("Soldiers: Anarchy of Oaths")
   love.graphics.draw("characters.png", 50, 50)

end
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: What are 'nil' errors?

Post by OmarShehata »

Aside from the problem TheDeskPop mentioned, this part makes little sense:

Code: Select all

player.characters = love.graphics.newImage("characters.png")
 player.left1 = love.graphics.newQuad(10, 30, 91, 170, 550, 170) --(10, 30, 91, 170, 550, 170)
 love.graphics.newImage("characters.png")
You first create "characters" inside of player, and load the image "characters.png". So far so good.

Then on the third line, you load the same image again, but you don't put it anywhere..just for the sake of it? Why would you do that?

Anyway, then when you want to draw this "characters.png", you attempt to do so by:

love.graphics.drawq(characters.png,50,50);

Why would you assume that will work? You never declare "characters" as a table, either globally or locally. "characters" is a key inside of the player table which points to the "characters.png" image.

Making sure you have a solid understanding of the basics will really save you a lot of headaches like this.
User avatar
Mogex
Prole
Posts: 15
Joined: Thu Dec 06, 2012 2:13 am

Re: What are 'nil' errors?

Post by Mogex »

OmarShehata wrote:Aside from the problem TheDeskPop mentioned, this part makes little sense:

Code: Select all

player.characters = love.graphics.newImage("characters.png")
 player.left1 = love.graphics.newQuad(10, 30, 91, 170, 550, 170) --(10, 30, 91, 170, 550, 170)
 love.graphics.newImage("characters.png")
You first create "characters" inside of player, and load the image "characters.png". So far so good.

Then on the third line, you load the same image again, but you don't put it anywhere..just for the sake of it? Why would you do that?

Testing on different ways to declare characters.png

Anyway, then when you want to draw this "characters.png", you attempt to do so by:

love.graphics.drawq(characters.png,50,50);

Why would you assume that will work? You never declare "characters" as a table, either globally or locally. "characters" is a key inside of the player table which points to the "characters.png" image.

So, instead of using "love.graphics.drawq(characters.png,50,50);" i should do it like "love.graphics.drawq(player.image,50,50);"
Given I've changed the table object from "character" to "image"?


Making sure you have a solid understanding of the basics will really save you a lot of headaches like this.
User avatar
Mogex
Prole
Posts: 15
Joined: Thu Dec 06, 2012 2:13 am

Re: What are 'nil' errors?

Post by Mogex »

Oh and I've changed it from drawq to draw temporarily.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests