the ERROR:
Error
Resources/anim8.lua:36: frameWidth should be a number, was "nil"
Traceback
[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'error'
Resources/anim8.lua:36: in function 'assertPositiveInteger'
Resources/anim8.lua:101: in function 'newGrid'
main.lua:12: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'
My oringinal code:
function love.load()
anim8 = require 'Resources/anim8'
love.graphics.setDefaultFilter("nearest", "nearest")
player = {}
player.x = 400
player.y = 350
player.speed = 7.5
gravity = 0
isJumping = false
jumpHeight = 100
player.grid = anim8.newGrid( )
player.sprite = love.graphics.newImage('Lua ig assets/Sprites/Swordsman.png')
player.spriteSheet = love.graphics.newImage('Lua ig assets/Sprites/Swordsman run spritesheet.png')
player.grid = anim8.newGrid( 48, 48, player.spriteSheet:getWidth(), player.spriteSheet:getHeight() )
player.animations = {}
player.animations.left = anim8.newAnimation( player.grid('1-8', 2), 0.2 )
player.animations.right = anim8.newAnimation(player.grid('1-8', 1), 0.2 )
player.anim = player.animations.left
end
function love.update(dt)
local isMoving = false
if love.keyboard.isDown("d") then
player.x = player.x + player.speed
player.anim = player.animations.right
isMoving = true
end
if love.keyboard.isDown("a") then
player.x = player.x - player.speed
player.anim = player.animations.left
isMoving = true
end
if love.keyboard.isDown("space") and not isJumping then
gravity = -10
isJumping = true
end
if isJumping then
player.y = player.y + gravity
gravity = gravity + 0.5
if player.y > 350 then
player.y = 350
gravity = 0
isJumping = false
end
end
if isMoving == false then
player.anim:gotoFrame(9)
end
player.anim:update(dt)
end
function love.draw()
player.anim:draw(player.spriteSheet, player.x, player.y, nil, 10)
end
Please help with my code
Re: Please help with my code
I don’t k is what anim8 is, but it expects its first parameter to be a positive integer and you aren’t passing anything.
-
- Prole
- Posts: 2
- Joined: Fri Feb 02, 2024 9:48 am
Re: Please help with my code
I follow Chalacade's turtorial for this code, if possible please point out the wrong part and rewrite it. Thank you
Re: Please help with my code
Code: Select all
Error
Resources/anim8.lua:36: frameWidth should be a number, was "nil"
to figure out which function you can look further in the error message :
Code: Select all
Resources/anim8.lua:101: in function 'newGrid'
main.lua:12: in function 'load'
lo and behold:
Code: Select all
jumpHeight = 100
player.grid = anim8.newGrid( )
basically the error message and stack trace is there for you, the developer that run into an error, you can learn a lot from it.
Who is online
Users browsing this forum: Bing [Bot] and 4 guests