Need help with another error

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
PedroChurro
Prole
Posts: 25
Joined: Tue Oct 09, 2012 8:22 pm
Location: In my room

Need help with another error

Post by PedroChurro » Fri Oct 12, 2012 5:12 pm

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:

Code: Select all

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'
Say if wou wanna take a look at the code.
I try to make games.

User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Need help with another error

Post by Nixola » Fri Oct 12, 2012 5:14 pm

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

User avatar
PedroChurro
Prole
Posts: 25
Joined: Tue Oct 09, 2012 8:22 pm
Location: In my room

Re: Need help with another error

Post by PedroChurro » Fri Oct 12, 2012 5:20 pm

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)
I try to make games.

User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Need help with another error

Post by Nixola » Fri Oct 12, 2012 5:38 pm

...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

User avatar
PedroChurro
Prole
Posts: 25
Joined: Tue Oct 09, 2012 8:22 pm
Location: In my room

Re: Need help with another error

Post by PedroChurro » Fri Oct 12, 2012 5:54 pm

Here is the main.lua and the map.lua:

Code: Select all

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

Code: Select all



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  
I try to make games.

User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Need help with another error

Post by Nixola » Fri Oct 12, 2012 5:58 pm

Menu.lua, :18 and :20, replace "v.medium" with "medium"
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

User avatar
PedroChurro
Prole
Posts: 25
Joined: Tue Oct 09, 2012 8:22 pm
Location: In my room

Re: Need help with another error

Post by PedroChurro » Fri Oct 12, 2012 6:00 pm

Nixola wrote:Menu.lua, :18 and :20, replace "v.medium" with "medium"
One more question answeared, over 9000 to go! Thanks!
I try to make games.

Post Reply

Who is online

Users browsing this forum: No registered users and 61 guests