Results 1 to 3 of 3

Thread: debug

                  
   
  1. #1
    DCEmu Newbie
    Join Date
    Mar 2006
    Posts
    5
    Rep Power
    0

    Question debug

    would someone be able to degug my code
    i think something is wrong with my random number thing

    Code:
    DRAW = Image.load("PICS/DRAW.JPG") 
    WIN = Image.load("PICS/WIN.JPG") 
    LOSE = Image.load("PICS/LOSE.JPG") 
    
    while true do 
    
    screen:clear() 
    
    pad = Controls.read() 
    
    -- X 
    if pad:cross() then 
    break 
    end 
    
    a = math.random(3)
    
    if a == 1 then 
    screen:blit(0,0,WIN) 
    end 
    
    if a == 2 then 
    screen:blit(0,0,LOSE) 
    end 
    
    if a == 3 then 
    screen:blit(0,0,DRAW) 
    end 
    
    screen.waitVblankStart() 
    screen.flip() 
    
    end
    thx

  2. #2
    DCEmu Pro b8a's Avatar
    Join Date
    Nov 2005
    Posts
    516
    Rep Power
    70

    Default

    I don't have any experience with Lua, so sorry if this doesn't help, but the way I've always been told is the standard for generating random numbers in other languages is
    Code:
    math.random()*3
    which should give you a floating point number between 0 and 1, multiplied by three, ultimately giving you a floating point number between 0 and 3. So to generate an integer just round the result
    Code:
    math.round(math.random()*3)
    The documentation I have doesn't list math.round as being available, but if it isn't you can use either math.ceil or math.floor to descriminate between rounding up or down respectively.

    But, looking at the Lua documentation, the way you coded it looks like it should be valid... But, in the past I've had problem with random numbers when I haven't stuck to this methoud, so hope it helps...

  3. #3
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    83

    Default

    The rand function looks correct.
    What numbers are you getting and try seeding the random function.

    edit:
    Nevermind, the rand function works 100%. The problem is your while loop logic which I leave you to fix as a learning exercise.

    I would guess that you have flicking pictures rather then a constant image.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •