code:
Player = {}
function Player:load()
self.x = 100
self.y = 0
self.width = 20
self.height = 60
self.xVel = 0
self.yVel = 0
self.maxSpeed = 200
self.acceleration = 4000
self.friction = 3500
self.physics = {}
self.physics.body = love.physics.newBody(World, self.x, self.y, "dynamic")
self.physics.body:setFixedRotation(true)
self.physics.shape = love.physics.newRectangleShape(self.width, self.height)
self.physics.fixture = love.physics.newFixture(self.physics.body, self.physics.shape)
end
function Player:update(dt)
self.syncPhysics()
end
function Player:syncPhysics()
self.x, self.y = self.physics.body:getPosition()
self.physics.body:setLinearVelocity(self.xVel, self.yVel)
end
function Player:draw()
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
end
Issue:
In function Player:draw()
the "love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)" line when compiling code cant access the values which added in function Player:load like self.x, self.y, etc.
Error
player.lua:31: bad argument #2 to 'rectangle' (number expected, got nil)
Traceback
[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'rectangle'
player.lua:31: in function 'draw'
main.lua:23: in function 'draw'
[love "callbacks.lua"]:168: in function <[love "callbacks.lua"]:144>
[C]: in function 'xpcall'
(Using STI)
Code wont detecting values
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Code wont detecting values
Code: Select all
function Player:update(dt)
self:syncPhysics() -- was function, not method
end
Otherwise attach the .love file, not just (probably) the part without errors.
Who is online
Users browsing this forum: No registered users and 6 guests