Can't call table values??
Posted: Fri Jul 19, 2024 12:47 am
I am making a game thats like smash bros mixed with the American revolution but anyway, I am using some libraries and one of them is for a camera that follows the player. I followed this tutorial when setting it up: [youtube]https://www.youtube.com/watch?[/youtube]v=F3zKl70RJlk&list=PLqPLyUreLV8DrLcLvQQ64Uz_h_JGLgGg2&index=7 and I worked while I was on replit. But when I switched to ZeroBrane Studio it came up with this error:
Error: main.lua:9: attempt to call global 'camera' (a table value)
stack traceback:
[love "boot.lua"]:352: in function 'camera'
main.lua:9: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[love "boot.lua"]:368: in function <[love "boot.lua"]:355>
[C]: in function 'xpcall'
Program completed in 10.46 seconds (pid: 5886).
Again this was never an issue before and as far as im aware it only effects the camera
here is my code "british" is the player
oad()
anim8 = require 'libraries/anim8'
camera = require 'libraries/camera'
wf = require 'libraries/windfield'
world = wf.newWorld(0, 5000)
-- Declare open source code above this line /\
love.graphics.setDefaultFilter('nearest', 'nearest') -- Makes the images look crisper and not blurry
cam = camera()
british = {}
british.x = 400
british.y = 200
british.speed = 140
british.collider = world:newBSGRectangleCollider(british.x, british.y, 50, 39, 5)
british.collider:setFixedRotation(true)
map = love.graphics.newImage("Maps/Plains map.png")
british.spriteSheet = love.graphics.newImage("sprites/British musketeer1-sheet-sheet.png")
british.grid = anim8.newGrid(50, 40, british.spriteSheet:getWidth(), british.spriteSheet:getHeight())
british.animations = {}
british.animations.walkRight = anim8.newAnimation(british.grid('1-10', 1), 0.15)
british.animations.walkLeft = anim8.newAnimation(british.grid('50-40', 1), 0.15)
british.animations.jumpRight = anim8.newAnimation(british.grid('12-16', 1), 0.15)
british.animations.jumpLeft = anim8.newAnimation(british.grid('36-40', 1), 0.15)
british.animations.idleRight = anim8.newAnimation(british.grid('1-1', 1), 0.15)
british.animations.idleLeft = anim8.newAnimation(british.grid('50-50', 1), 0.15)
british.animations.fireRight = anim8.newAnimation(british.grid('17-18', 1), 0.15)
british.anim = british.animations.walkRight
local ground = world:newRectangleCollider(0, 480, 800, 120)
ground:setType('static')
ground.y = 120
end
function love.update(dt)
local ismoving = false
local vx = 0 -- velocity of x
local vy = 0 -- velocity of y
if love.keyboard.isDown("d") then
vx = british.speed
british.anim = british.animations.walkRight
ismoving = true
end
if love.keyboard.isDown("a") then
vx = british.speed * -1 --Turns the velocity negitive to move left
british.anim = british.animations.walkLeft
ismoving = true
end
if love.keyboard.isDown("s") then
vy = british.speed
end
-- if love.keyboard.isDown("w") and canjump == true then
--vy = british.speed * -3 --Turns the velocity negitive to jump up
-- british:applyForce(0, -british.speed * 3)
-- british.anim = british.animations.jumpRight
-- end
if love.keyboard.isDown("space") then
british.anim = british.animations.fireRight
end
british.collider:setLinearVelocity(vx, vy)
if ismoving == false then
british.anim:gotoFrame(1)
end
if british.y < 400 then
canjump = false
elseif british.y > 400 then
canjump = true
end
if canjump == false then
vy = british.speed * 4
end
british.anim:update(dt)
world:update(dt)
british.x = british.collider:getX()
british.y = british.collider:getY()
cam:lookAt(british.x, british.y)
local w = love.graphics.getWidth()
local h = love.graphics.getHeight()
if cam.x < w/2 then
cam.x = w/2
end
if cam.y < h/2 then
cam.y = h/2
end
local mapW = 800
local mapH = 600
if cam.x > (mapW - w/2) then
cam.x = (mapW - w/2)
end
if cam.y > (mapH - h/2) then
cam.y = (mapH - h/2)
end
end
function love.draw()
cam:attach()
love.graphics.draw(map, 0, 0)
british.anim:draw(british.spriteSheet, british.x, british.y, nil, nil, nil, 16.5, 19.5)
world:draw()
cam:detach()
end
Again this was only a problem when I moved from Replit to ZeroBrane Studio...
Error: main.lua:9: attempt to call global 'camera' (a table value)
stack traceback:
[love "boot.lua"]:352: in function 'camera'
main.lua:9: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[love "boot.lua"]:368: in function <[love "boot.lua"]:355>
[C]: in function 'xpcall'
Program completed in 10.46 seconds (pid: 5886).
Again this was never an issue before and as far as im aware it only effects the camera
here is my code "british" is the player
oad()
anim8 = require 'libraries/anim8'
camera = require 'libraries/camera'
wf = require 'libraries/windfield'
world = wf.newWorld(0, 5000)
-- Declare open source code above this line /\
love.graphics.setDefaultFilter('nearest', 'nearest') -- Makes the images look crisper and not blurry
cam = camera()
british = {}
british.x = 400
british.y = 200
british.speed = 140
british.collider = world:newBSGRectangleCollider(british.x, british.y, 50, 39, 5)
british.collider:setFixedRotation(true)
map = love.graphics.newImage("Maps/Plains map.png")
british.spriteSheet = love.graphics.newImage("sprites/British musketeer1-sheet-sheet.png")
british.grid = anim8.newGrid(50, 40, british.spriteSheet:getWidth(), british.spriteSheet:getHeight())
british.animations = {}
british.animations.walkRight = anim8.newAnimation(british.grid('1-10', 1), 0.15)
british.animations.walkLeft = anim8.newAnimation(british.grid('50-40', 1), 0.15)
british.animations.jumpRight = anim8.newAnimation(british.grid('12-16', 1), 0.15)
british.animations.jumpLeft = anim8.newAnimation(british.grid('36-40', 1), 0.15)
british.animations.idleRight = anim8.newAnimation(british.grid('1-1', 1), 0.15)
british.animations.idleLeft = anim8.newAnimation(british.grid('50-50', 1), 0.15)
british.animations.fireRight = anim8.newAnimation(british.grid('17-18', 1), 0.15)
british.anim = british.animations.walkRight
local ground = world:newRectangleCollider(0, 480, 800, 120)
ground:setType('static')
ground.y = 120
end
function love.update(dt)
local ismoving = false
local vx = 0 -- velocity of x
local vy = 0 -- velocity of y
if love.keyboard.isDown("d") then
vx = british.speed
british.anim = british.animations.walkRight
ismoving = true
end
if love.keyboard.isDown("a") then
vx = british.speed * -1 --Turns the velocity negitive to move left
british.anim = british.animations.walkLeft
ismoving = true
end
if love.keyboard.isDown("s") then
vy = british.speed
end
-- if love.keyboard.isDown("w") and canjump == true then
--vy = british.speed * -3 --Turns the velocity negitive to jump up
-- british:applyForce(0, -british.speed * 3)
-- british.anim = british.animations.jumpRight
-- end
if love.keyboard.isDown("space") then
british.anim = british.animations.fireRight
end
british.collider:setLinearVelocity(vx, vy)
if ismoving == false then
british.anim:gotoFrame(1)
end
if british.y < 400 then
canjump = false
elseif british.y > 400 then
canjump = true
end
if canjump == false then
vy = british.speed * 4
end
british.anim:update(dt)
world:update(dt)
british.x = british.collider:getX()
british.y = british.collider:getY()
cam:lookAt(british.x, british.y)
local w = love.graphics.getWidth()
local h = love.graphics.getHeight()
if cam.x < w/2 then
cam.x = w/2
end
if cam.y < h/2 then
cam.y = h/2
end
local mapW = 800
local mapH = 600
if cam.x > (mapW - w/2) then
cam.x = (mapW - w/2)
end
if cam.y > (mapH - h/2) then
cam.y = (mapH - h/2)
end
end
function love.draw()
cam:attach()
love.graphics.draw(map, 0, 0)
british.anim:draw(british.spriteSheet, british.x, british.y, nil, nil, nil, 16.5, 19.5)
world:draw()
cam:detach()
end
Again this was only a problem when I moved from Replit to ZeroBrane Studio...