 
                
                14 posts
                
             
            
                Posted 21 October 2012 - 02:01 AM
                How do I fix this.
Here is my code i need help pls.
red = Color.new(255,0,0)
black = Color.new(0,0,0)
white = Color.new(255,255,255)
menustatus = 1
while true do
screen:clear(black)
pad = Controls.read()
if pad:up() then
menustatus = menustatus - 1
screen.waitVblankStart(4) 
end
if pad:down() then
menustatus = menustatus + 1
screen.waitVblankStart(4) 
end
color={white, white, white}
screen:print(50, 50, "Play", color[1])
screen:print(50,60,"Options", color[2])
screen:print(50,70,"Exit", color[3])
color[menustatus]=red
if menustatus == 1 then
if pad:cross() then
dofile("Game.lua")
if menustatus == 2 then
if pad:cross() then
–insert options here
end
end
if menustatus == 3 then
if pad:cross() then
break
end
end
if menustatus <= 0 then
menustatus = 3
end
if menustatus => 4 then
menustatus = 1
end
screen.flip()
screen.waitVblankStart()
end
                
             
         
        
        
            
            
                
                     
                
                8543 posts
                
             
            
                Posted 21 October 2012 - 02:36 AM
                if menustatus >= 4 then
The greater than sign must come before the equals sign.
                
             
         
        
        
            
            
                
                     
                
                2005 posts
                
             
            
                Posted 21 October 2012 - 04:28 AM
                Are you sure this is working?
                
             
         
        
        
            
            
                
                     
                
                14 posts
                
             
            
                Posted 23 October 2012 - 10:51 PM
                Are you sure this is working?
Why is there something else wrong?
 
         
        
        
            
            
                
                     
                
                2005 posts
                
             
            
                Posted 23 October 2012 - 11:10 PM
                That is what I was asking.
                
             
         
        
        
            
            
                
                     
                
                14 posts
                
             
            
                Posted 23 October 2012 - 11:16 PM
                Let me see
                
             
         
        
        
            
            
                
                     
                
                14 posts
                
             
            
                Posted 23 October 2012 - 11:35 PM
                C'mon no errors but no menu shows up.
new menu……
blue = Color.new(0, 50, 175)
white = Color.new(255,255,255)
ms = 1
mms = 5
oldpad = Controls.read()
while true do
screen:clear()
pad = Controls.read()
if pad:up() and oldpad:up() ~= pad:up() then
ms = ms - 1
end
if pad:down() and oldpad:down() ~= pad:down() then
ms = ms + 1
end
if ms > mms then
ms = 1
elseif ms <= 0 then
ms = mms
end
mc = { white,white,white,white,white }
mc[ms] = blue
screen:print(98,107,"Game",mc[1])
screen:print(98,117,"Opti on 2",mc[2])
screen:print(98,127,"Opti on 3",mc[3])
screen:print(98,137,"Opti on 4",mc[4])
screen:print(98,147,"Opti on 5",mc[5])
if pad:cross() and not oldpad:cross() and ms == 1 then
dofile("Game.lua")
end
if pad:cross() and not oldpad:cross() and ms == 2 then
–Paste code that happens when X is pressed over option 2
end
if pad:cross() and not oldpad:cross() and ms == 3 then
–Paste code that happens when X is pressed over option 3
end
if pad:cross() and not oldpad:cross() and ms == 4 then
–Paste code that happens when X is pressed over option 4
end
if pad:cross() and not oldpad:cross() and ms == 5 then
break
end
if ms <= 0 then
ms = 5
end
if ms >= 6 then
ms = 1
end
screen.waitVblankStart()
screen.flip()
oldpad = pad
end
When I click option 5 it says error:(null)
What its sposed to do is break (stop) the entire code and exit game how do i fix?
                
             
         
        
        
            
            
                
                     
                
                2005 posts
                
             
            
                Posted 23 October 2012 - 11:43 PM
                Using break takes you out of the innermost current loop.  The innermost current loop in this case is the while true do end, so you skip to the bottom of the program and lua can't find any more lines of code there.  Perhaps you should use return false or something.
                
             
         
        
        
            
            
                
                     
                
                14 posts
                
             
            
                Posted 23 October 2012 - 11:57 PM
                Using break takes you out of the innermost current loop.  The innermost current loop in this case is the while true do end, so you skip to the bottom of the program and lua can't find any more lines of code there.  Perhaps you should use return false or something.
I'll try, but would this be right?
if pad:cross() and not oldpad:cross() and ms == 1 thendofile("Game.lua")endIf I wanted to load a game lua file up? 
         
        
        
            
            
                
                     
                
                2005 posts
                
             
            
                Posted 24 October 2012 - 12:05 AM
                Not too familiar with the Controls API which you're using.  So can't say for sure whether any of that works.  But dofile(filename) should work as long as the filename is right and the file is lua.
                
             
         
        
        
            
            
                
                     
                
                14 posts
                
             
            
                Posted 24 October 2012 - 12:33 AM
                i respect everyone here it has a great lasting community that words will not describe
                
             
         
        
        
            
            
                
                     
                
                14 posts
                
             
            
                Posted 24 October 2012 - 11:05 PM
                Error no loop to break near end what now?
–Created by dragonxtamer596
–On the 10/18/12
Room_width = 480 
Room_height = 272 
player1x =240
player1y =136
—Load Sprites — 
background =Image.load ("images/Background.PNG")
player1=Image.load("images/Player1.PNG")
——functions 
function checkcontrols()
pad = Controls.read()
if pad:start() then
exitgame = 1
end
if pad:right() then
player1x = player1x -2
end
if pad:left() then
player1x = player1x +2
end
if pad:up() then
player1y = player1y - 2
end
if pad:down() then
player1y = player1y +2
end
end
function drawall() 
screen:blit (0,0,background)
screen:blit(player1x,player1y,player1)
screen.waitVblankStart()
screen.flip()
 end 
– MAIN LOOP 
while true do 
end
checkcontrols() 
 drawall()
if pad:start() == 1 then
break
end
                
             
         
        
        
            
            
                
                     
                
                8543 posts
                
             
            
                Posted 24 October 2012 - 11:49 PM
                You have while true do end as your main loop, then some code sticking out at the end of the file. Get rid of the end right after the while true do.
In fact, if you break out of it after once through like that, you may as well just get rid of the loop, and the break altogether.
                
             
         
        
        
            
            
                
                     
                
                14 posts
                
             
            
                Posted 25 October 2012 - 12:05 AM
                Also I'm making a random number generator 
error index lua 24 method must be called with a colon
code what do i do?
– My Second Lua Program
– Author: Dragonxtamer596
red = Color.new(255, 0, 0) 
function checkcontrols()
pad = Controls.read()
if pad:start() then
end
exitgame = 1
end
local choice = math.random(1, 3) –Chooses a random number between 1 and 3.
if choice == 1 then 
screen.print(200, 100, "1", red) 
end
if choice == 2 then 
screen.print(200, 100, "2", red) 
end
if choice == 3 then 
screen.print(200, 100, "3", red) 
end
screen.flip() 
while true do
screen.waitVblankStart()
end
checkcontrols() 
drawall()
if pad:start() == 1 then
end
while true do
break
end
                
             
         
        
        
            
            
                
                     
                
                14 posts
                
             
            
                Posted 25 October 2012 - 02:12 AM
                
– My Second Lua Program
– Author: Dragonxtamer596
red = Color.new(255, 0, 0) 
function checkcontrols()
pad = Controls.read()
if pad:start() then
end
exitgame = 1
end
local choice = math.random(1, 3) –Chooses a random number between 1 and 3.
if choice == 1 then 
screen:print(200, 100, "1", red) 
end
if choice == 2 then 
screen:print(200, 100, "2", red) 
end
if choice == 3 then 
screen:print(200, 100, "3", red) 
end
screen.flip() 
while true do
screen.waitVblankStart()
end
checkcontrols() 
drawall()
if pad:start() then
end
while true do
break
end 
Ok i fixed it…. now how do i press a button to generate a new random number? 
         
        
        
            
            
                
                     
                
                2088 posts
                
                    
                        Location
                        South Africa
                    
                
             
            
                Posted 25 October 2012 - 07:10 AM
                Please put your code in 
[code] -- code here [/code*] (without the *)
 tags and state what you need help with and / or what your error is. This is very difficult too read.