Error regarding basic main menu and tables SOLVED
Posted: Wed Nov 14, 2012 5:32 pm
Hello. New here. Got into starting to learn about love a few weeks ago. I'm no code monkey by any means, my previous experience being mostly in modding and the making of 2d graphics (which I have over the years gotten quite good at). So, I'm no coder by any previous experience. This means that when I try to learn things I tend to mess up and then not know what the problem is, so I might be here asking stupid questions a lot as I'm trying to learn the basics from the ground up. I learn mostly by doing, so I have followed some basic tutorials and succeeded with some basic things, but now I'm actually trying to do some things that I might in some form actually end up using for something, not just "red rectangle can move around". This means I've started building a main menu, which will feature some buttons for things that might at some point be scripted assuming I do not ragequit along the way. As such, I have attempted to use some basic table management in order to make some form of main menu. In part, this is in order to save codespace, and in part it is to familiarise myself with the use of tables in luascript.
The love file I have here produces a syntax error. I do not know what it wants me to do to solve it, and therefore I'm asking for help now. The main menu is image-based, featuring a few buttons and a background texture. The love file features code that is supposed to make the buttons glow when the mouse is hovering over them, which is what is problematic. If I comment out all the code for drawing the buttons, the script runs and the background texture renders along with the cursor. That stuff works. The only thing that is scripted for at this point is the main menu. The image folder in the love also contains some relics that are not used.
The error I get is:
syntax error: menu.lua:60 ')' expected near main_menu_buttons
What follows is the functions dealing with said table to give some context:
And here is the block that the error traces back to, starting at line 56.
The code below this is unrelated and works.
The love file I have here produces a syntax error. I do not know what it wants me to do to solve it, and therefore I'm asking for help now. The main menu is image-based, featuring a few buttons and a background texture. The love file features code that is supposed to make the buttons glow when the mouse is hovering over them, which is what is problematic. If I comment out all the code for drawing the buttons, the script runs and the background texture renders along with the cursor. That stuff works. The only thing that is scripted for at this point is the main menu. The image folder in the love also contains some relics that are not used.
The error I get is:
syntax error: menu.lua:60 ')' expected near main_menu_buttons
What follows is the functions dealing with said table to give some context:
Code: Select all
function main_menu_buttons_load(number, width, height)
local CentralX = find_central_x()
local HalfWidth = width/2
for var = 1, number, 1 do
local var2 = var - 1
main_menu_buttons[var].X = CentralX - HalfWidth
main_menu_buttons[var].Y = 128 + var2 * 128
main_menu_buttons[var].RelaxedImage = love.graphics.newImage("images/mainmenubutton"..var..".png")
main_menu_buttons[var].HoverImage = love.graphics.newImage("images/mainmenubutton"..var.."hover.png")
main_menu_buttons[var].Width = width
main_menu_buttons[var].Height = height
main_menu_buttons[var].Hover = false
end
end
Code: Select all
function main_menu_buttons_update(number)
local MouseX = love.mouse.getX()
local MouseY = love.mouse.getY()
local var = 1
for var = 1, number, 1 do
if MouseX > main_menu_buttons[var].X
and MouseX < main_menu_buttons[var].X + main_menu_buttons[var].Width
and MouseY > main_menu_buttons[var].Y
and MouseY < main_menu_buttons[var].Y + main_menu_buttons[var].Height
then
main_menu_buttons[var].Hover = true
else
main_menu_buttons[var].Hover = false
end
end
end
Code: Select all
function main_menu_buttons_draw(number)
local var = 1
for var = 1, number, 1 do
if main_menu_buttons[var].Hover == true then
love.graphics.draw(main_menu_buttons[var].HoverImage, main_menu_buttons[var].X main_menu_buttons[var].Y)
else
love.graphics.draw(main_menu_buttons[var].RelaxedImage, main_menu_buttons[var].X main_menu_buttons[var].Y)
end
end
end