eyodood
eyodood

Reputation: 1

Cannot see buttons in Lua

I have added a logo and few buttons, such as PLAY and CREDITS. I do not receive any errors and I'm having a hard time seeing the problem, what am I missing?

--Background   
local bg = display.newImage("background.png")  
--Buttons  
local title  
local playBtn  
local creditsBtn

--Functions  
local Main=('')  
local startButtonListeners=('')  

--Start of Functions  
function Main()  
title= display.newImage("logo.png")  
playBtn= display.newImage("playbtn.png", 130, 248)  
creditsBtn= display.newImage("creditsbtn.png", 125, 316)
titleView= display.newGroup(title, playBtn, creditsBtn)    

startButtonListeners("add")  
end

Upvotes: 0

Views: 40

Answers (1)

George Pantazes
George Pantazes

Reputation: 1130

If that is your code in its entirety, you never called your main function, and in corona, you don't have to call a main function, main.lua is run at the beginning of your project. So try running your code like this

--Background   
local bg = display.newImage("background.png")  
--Buttons  
local title  
local playBtn  
local creditsBtn

--Functions  
local Main  
local startButtonListeners, anotherButtonListener

--Start of Functions  
Main = function()  
   title= display.newImage("logo.png")  
   playBtn= display.newImage("playbtn.png", 130, 248)  
   creditsBtn= display.newImage("creditsbtn.png", 125, 316)
   titleView= display.newGroup()    
   titleView:insert(title)
   titleView:insert(playBtn)
   titleView:insert(creditsBtn)

   playBtn:addEventListener("tap", startButtonListeners)
   --creditsBtn:addEventListener("tap", anotherButtonListener)
end

startButtonListeners = function(event)
   --Do something here
end
anotherButtonListener = function(event)
   --Do something for the credits here
end

Main()  --Remember to actually call Main to make it run

In Lua, there is no declared main function, it just runs everything in a sequence. Remember that you do not need to write a main function like you would in C, but more like Python, it will just run what you write.

EDIT: Why don't you post the errors you get so we can help you better? But scanning the code something definitely got past me. The newGroup line. Refer above for the edited code.

Upvotes: 2

Related Questions