Hi, first of all, sorry for being spamming(not really) this forum with questions, but yeah, I have another error I can't solve.
So, I'm learning how to make a menu, and, this happens when I click the "Quit" button:
Error
menu.lua:18 attempt to index field 'medium' (a nil value)
Traceback
menu.lua:18 in function 'button_click'
main.lua:36: in function 'mousepressed'
[C]: in function 'xpcall'
We need the code this time... Anyway, you probably wrote something like "a_table.medium[var]" without writing that "a_table.medium" is a table (you did it in line 18, if oyu don't know)
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Nixola wrote:We need the code this time... Anyway, you probably wrote something like "a_table.medium[var]" without writing that "a_table.medium" is a table (you did it in line 18, if oyu don't know)
Line 18 of menu.lua: x < v.x + v.medium:getWidth(v.text) and
Line 36 of main.lua: button_click(x,y)
The variable: medium = love.graphics.newFont(35)
...Ok, you should really post more code. Anyway, you declared the global variable "medium", v (that is part of a For loop, I think) doesn't have a "medium" field
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
require 'player'
require 'map'
require 'menu'
function love.load()
medium = love.graphics.newFont(35)
gamestate = "menu"
--Buttons
button_spawn(5,200,"Start","start")
button_spawn(5,300,"Quit","quit")
end
function love.update(dt)
if gamestate == "playing" then
player_move(dt)
map_collide()
end
end
function love.draw()
if gamestate == "playing" then
player_draw()
end
if gamestate == "menu" then
button_draw()
end
end
function love.mousepressed(x,y)
if gamestate == "menu" then
button_click(x,y)
end
end
button = {}
function button_spawn(x,y,text,id)
table.insert(button, {x = x,y = y, text = text, id = id})
end
function button_draw()
for i,v in ipairs(button) do
love.graphics.setColor(255,255,255)
love.graphics.setFont(medium)
love.graphics.print(v.text,v.x,v.y)
end
end
function button_click(x,y)
for i,v in ipairs(button) do
if x > v.x and
x < v.x + v.medium:getWidth(v.text) and
y > v.y and
y < v.y + v.medium:getHeight() then
if v.id == "quit" then
love.event.push("quit")
end
end
end
end