I'm getting an error that says:
--------------------------------------------------------------------------------------------------------
grapics.lua:1265: bad argument #3 to 'print1' (number expected, got string)
Traceback
[C]: in function 'print1'
graphics.lua:1265: in function 'print'
menu.lua:12: in function 'button_draw'
main.lua:30: in function 'draw'
[C]: in function 'xpcall'
--------------------------------------------------------------------------------------------------------
I'll post my code for menu.lua and main.lua here:
main.lua
--------------------------------------------------------------------------------------------------------
require "player"
require "map"
require "menu"
function love.load()
medium = love.graphics.newFont(45)
love.graphics.setBackgroundColor(0,255,0)
base = 550
gamestate = "menu"
-- Buttons
button_spawn(10,50,"Start")
-- Loading
player.load()
end
function love.update(dt)
UPDATE(dt)
MAP_UPDATE()
end
function love.draw()
DRAW()
if gamestate == "menu" then
button_draw()
end
end
function love.keypressed(key, unicode)
end
function love.keyreleased(key)
end
--------------------------------------------------------------------------------------------------------
and menu.lua
--------------------------------------------------------------------------------------------------------
button = {}
function button_spawn(x,y,text)
table.insert(button, {x = x,y = y,text = text})
end
function button_draw()
for i,v in ipairs(button) do
love.graphics.setColor(0,0,0)
love.graphics.setFont(medium)
love.graphics.print(v.x,v.y,v.text)
end
end
--------------------------------------------------------------------------------------------------------
Everything was working until I made/tried to make a table.
I don't know what's wrong and if you do please help me.
Thanks
Error
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Error
Welcome.
The solution: change
to
Could you if you have another problem in the future please upload a .love of your game as an attachment? That way we can help you much better than a dump of text in a forum post.
Please choose a more specific post title in the future. "Error" is unhelpful and confusing.
Also, this is the wrong forum (General), you should have posted it in Support & Development. On that forum is also a sticky topic with forum rules. Please read those before asking for help again. This sound a bit harsh, maybe, but in that way we can help you much better.
The solution: change
Code: Select all
love.graphics.print(v.x,v.y,v.text)
Code: Select all
love.graphics.print(v.text, v.x, v.y)
Could you if you have another problem in the future please upload a .love of your game as an attachment? That way we can help you much better than a dump of text in a forum post.
Please choose a more specific post title in the future. "Error" is unhelpful and confusing.
Also, this is the wrong forum (General), you should have posted it in Support & Development. On that forum is also a sticky topic with forum rules. Please read those before asking for help again. This sound a bit harsh, maybe, but in that way we can help you much better.
Last edited by Robin on Tue Apr 30, 2013 8:26 pm, edited 1 time in total.
Help us help you: attach a .love.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Error
Please use the code tags. It is very hard to read code when it's not formatted. (Beaten lololzors)
Your problem is right where the error tells you. Line 12 of menu.lua. You put the X and Y first before the string to print. The string should be first.
Should be:
Error screens are not just unhelpful gibberish. They tell you exactly where your error is occurring and where you should start. In this case the error is in your print call. Ignore the first part about "graphics.lua" as that's an internal file, just follow the trace downwards until you get to a file you actually made. In this case, menu.lua. Line 12. The love.graphics.print call.
You should hopefully be using a text editor that has line numbers as it will make it much easier to debug code when errors happen.
Your problem is right where the error tells you. Line 12 of menu.lua. You put the X and Y first before the string to print. The string should be first.
Code: Select all
love.graphics.print(v.x,v.y,v.text)
Code: Select all
love.graphics.print(v.text,v.x,v.y)
You should hopefully be using a text editor that has line numbers as it will make it much easier to debug code when errors happen.
Who is online
Users browsing this forum: Bing [Bot] and 1 guest