Okay, so I have just begun learning lua recently, and I am making a stupid app for practice/learning. I have this code:
Code:
--App by andyauff
--Version .02 of "Useless Music App", finished January , 2007
--define colors---------------------------------------------------
white = Color.new (255,255,255)
blue = Color.new (0,0,255)
black = Color.new (0,0,0)
red = Color.new (255,0,0)
green = Color.new (0,255,0)
yellow = Color.new (255,255,0)
purple = Color.new (255,0,255)
--create the menu function----------------------------------------
function drawMenu()
gamestate = "menu"
oldpad = Controls.read()
song = "mindwave"
selector = { image = Image.createEmpty (145,15), x = 147, y = 77}
selector.image:clear(yellow)
screen:clear(green)
pad = Controls.read()
screen:blit(selector.x,selector.y,selector.image)
screen:print(150,80,"Mindwave",blue)
screen:print(150,100,"Minute",blue)
--controls
if pad:up() and oldpad:up() ~= pad:up() then
selector.y = 77
song = "mindwave"
end
if pad:down() and oldpad:down() ~= pad:down() then
selector.y = 97
song = "minute"
end
if pad:cross() and oldpad:cross() ~= pad:cross() then
inGame()
end
screen.flip()
end
--create the game funtion------------------------------------------
function inGame()
gamestate = "start"
pad = Controls.read()
screen:clear(red)
screen:print(150,100,"To play song, press X.",green)
screen:print(150,120,"To pause song, press X again.",yellow)
screen:print(150,140,"Enjoy!",purple)
if pad:cross() and gamestate == "start" and song == "mindwave" then
Music.playFile("mindwave.mod", false)
gamestate = "playing"
end
if pad:cross() and gamestate == "start" and song == "minute" then
Music.playFile("minute.xm", false)
gamestate = "playing"
end
if pad:cross() and gamestate == "playing" then
Music.pause()
gamestate = "paused"
end
if pad:cross() and gamestate == "paused" then
Music.resume()
gamestate = "playing"
end
if pad:start() then
gamestate = "menu"
end
screen.flip()
end
--main loop---------------------------------------------------------
while true do
drawMenu()
oldpad = pad
end
First let me tell you what it is supposed to do- there is a start screen that is a menu with choices between 2 different songs to play. If you click (cross) on a song, it should go to a new screen that says "press x to play song, press x again to pause song, enjoy." The selected song should play once pressing cross, pause if cross is pressed again, and that's about it. I have many problems-the selector for the menu doesn't move, when I press X it sometimes plays music, sometimes it doesn't, and instead of pausing it stops it completely and starts back over when I press X again. Thanks for any help, I know this is confusing. Hopefully the code is at least sort of neat.