I am making a small game and keep getting this error when trying to make an error system.
main.lua:105: attempt to call upvalue 'error_result' (a string value)
[love "callbacks.lua"]:228: in function 'handler'
main.lua:105: in function <main.lua:103>
[C]: in function 'xpcall'
I am not quite sure what to do, it seems to work in another game I have been tweaking/editing.
I will post the code here.
code that causes the error inside of main.lua
Code: Select all
return function()
if error_result then
local result = error_result()
if result then
if result == "reload" then
Mod = nil
error_result = nil
else
if love.quit then
love.quit()
end
return result
end
end
else
local success, result = xpcall(mainLoop, Leggle.errorHandler)
if success then
return result
else
error_result = result
end
end
end
local function error_printer(msg, layer)
print((debug.traceback("Error: " .. tostring(msg), 1+(layer or 1)):gsub("\n[^\n]+$", "")))
end
Code: Select all
function Leggle.errorHandler(msg)
local copy_color = {1, 1, 1, 1}
local anim_index = 1
--local font = love.graphics.newFont("assets/fonts/main.ttf", 32, "mono")
--local smaller_font = love.graphics.newFont("assets/fonts/main.ttf", 16, "mono")
msg = tostring(msg or "nil")
error_printer(msg, 2)
if not love.window or not love.graphics or not love.event then
return
end
local width = SCREEN_WIDTH
local height = SCREEN_HEIGHT
local window_scale = 1
if Leggle.Config then
window_scale = Leggle.Config["windowScale"] or 1
if window_scale ~= 1 then
local width = SCREEN_WIDTH * window_scale
local height = SCREEN_HEIGHT * window_scale
end
end
if not love.window.isOpen() then
local success, status = pcall(love.window.setMode, width, height)
if not success or not status then
return
end
end
-- Reset state.
if Input then Input.clear(nil, true) end
if love.mouse then
love.mouse.setVisible(true)
love.mouse.setGrabbed(false)
love.mouse.setRelativeMode(false)
if love.mouse.isCursorSupported() then
love.mouse.setCursor()
end
end
if love.joystick then
-- Stop all joystick vibrations.
for i,v in ipairs(love.joystick.getJoysticks()) do
v:setVibration()
end
end
if love.audio then love.audio.stop() end
love.graphics.reset()
love.graphics.setColor(1, 1, 1, 1)
local trace = debug.traceback("", 2)
love.graphics.origin()
local split = Utils.split(msg, ": ")
local function draw()
local pos = 32
local ypos = pos
love.graphics.origin()
love.graphics.clear(0, 0, 0, 1)
love.graphics.scale(window_scale)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setFont(smaller_font)
love.graphics.printf("Leggle v" .. tostring(Leggle.Version), -20, 10, 640, "right")
love.graphics.setFont(font)
local _,lines = font:getWrap("Error at "..split[#split-1].." - "..split[#split], 640 - pos)
love.graphics.printf({"Error at ", {0.6, 0.6, 0.6, 1}, split[#split-1], {1, 1, 1, 1}, " - " .. split[#split]}, pos, ypos, 640 - pos)
ypos = ypos + (32 * #lines)
for l in trace:gmatch("(.-)\n") do
if not l:match("boot.lua") then
if l:match("stack traceback:") then
love.graphics.setFont(font)
love.graphics.printf("Traceback:", pos, ypos, 640 - pos)
ypos = ypos + 32
else
love.graphics.setFont(smaller_font)
love.graphics.printf(l, pos, ypos, 640 - pos)
ypos = ypos + 16
end
end
end
-- DT shouldnt exceed 30FPS
DT = math.min(love.timer.getDelta(), 1/30)
copy_color[1] = copy_color[1] + (DT * 2)
copy_color[3] = copy_color[3] + (DT * 2)
--love.graphics.setFont(smaller_font)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.print("Press ESC to restart the game", 8, 480 - 40)
love.graphics.setColor(copy_color)
love.graphics.print("Press CTRL+C to copy traceback to clipboard", 8, 480 - 20)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.present()
end
local function copyToClipboard()
if not love.system then return end
copy_color = {0, 1, 0, 1}
love.system.setClipboardText(trace)
draw()
end
return function()
if love.graphics.isActive() and love.graphics.getCanvas() then
love.graphics.setCanvas()
end
love.event.pump()
for e, a, b, c in love.event.poll() do
if e == "quit" then
return 1
elseif e == "keypressed" and a == "escape" then
return "reload"
elseif e == "keypressed" and a == "c" and Input.ctrl() then
copyToClipboard()
elseif e == "touchpressed" then
local name = love.window.getTitle()
if #name == 0 or name == "Untitled" then name = "Game" end
local buttons = {"OK", "Cancel"}
if love.system then
buttons[3] = "Copy to clipboard"
end
local pressed = love.window.showMessageBox("Quit "..name.."?", "", buttons)
if pressed == 1 then
return 1
elseif pressed == 3 then
copyToClipboard()
end
end
end
if love.timer then
DT = love.timer.step()
end
draw()
love.timer.sleep(0.01)
end
end