Results 1 to 4 of 4

Thread: Lua Script Slow on PSP

  
  1. #1
    Persian 117 is offline -Hacks Member
    Join Date
    Jan 2007
    Location
    Bowels of hell
    Posts
    272
    Rep Power
    13

    Default

    I wrote a LUA script (began learning LUA 2/3 hours ago) and its fast on the pc but not on the psp. Also the music is slow and sounds bad. Can somebody help me with this one (tell me what I did wrong/ any bad lua habits etc..)

    Code:
    -- Declare Some Colors
    green = Color.new(0,225,0) 
    red = Color.new(225,0,0) 
    white = Color.new(225,225,225)
    
    -- Make a red box 50,50 Pixels and call it player
    player = Image.createEmpty(5,5)
    player:clear(white)
    
    -- Position this box
    Player = { x = 240, y = 0 }
    
    -- Make a function to move the box
    function movePlayer()
    pad = Controls.read()
    if pad:right() then
    Player.y = Player.y + 5
    end
    if pad:left() then
    Player.y = Player.y - 5
    end
    if pad:down() then
    Player.x = Player.x + 5
    end
    if pad:up() then
    Player.x = Player.x - 5
    end
    
    -- Make sure the box doesn't go beyond the screen
    if pad:up() and Player.x < 0 then
    
    Player.x = 0
    end
    
    if pad:left() and Player.y < 0 then
    
    Player.y = 0
    end
    
    rightborder = 480 - player:width()
    
    downborder = 272 - player:height()
    
    if pad:right() and Player.y > rightborder then
    	
    Player.y = rightborder
    end
    
    if pad:down() and Player.x > downborder then
    
    Player.x = downborder
    end
    
    -- This ends movePlayer()
    end
    
    
    -- Play a nice little song
    Music.playFile("song.xm", true)
    
    -- This stuff from HERE down is in a constant loop
    while true do 
    
    -- Clear the screen :P
    screen:clear()
    
    -- Starts the function
    movePlayer()
    
    star = Image.load("starfield.jpg")
    screen:blit(0,0,star)
    screen:blit(Player.y,Player.x,player)
    
    -- Prints the location of the box we created
    screen:print(150,5,"X:" .. Player.x,white)
    screen:print(274,5,"Y:" .. Player.y,white)
    
    -- Make sure the program won't close
    screen.waitVblankStart()
    
    -- Display all the stuff on the screen
    screen.flip()
    end
    Audio: stranglehold.xm in the zip file http://www.luaplayer.org/luaplayerwindows-0.20.zip

    Image: http://img266.imageshack.us/img266/1...arfield6mu.jpg

    Thanks :)

    - Tyler


  2. #2
    ST@TIC is offline -Hacks Newbie
    Join Date
    Nov 2006
    Location
    South Africa
    Posts
    39
    Rep Power
    13

    Default

    I would surgest puttinh the
    star = Image.load("starfield.jpg")
    before the main loop as u are declaring it over and over again
    see if that helps

    \"Death be not proud, some have called thee mighty and great, thou art not so\"

  3. #3
    Persian 117 is offline -Hacks Member
    Join Date
    Jan 2007
    Location
    Bowels of hell
    Posts
    272
    Rep Power
    13

    Default

    thanks a bunch :)

  4. #4
    Anti-QJ is offline -Hacks Newbie
    Join Date
    Mar 2007
    Posts
    18
    Rep Power
    0

    Default

    Also, Your LUA scripts will run faster on PC since your using your PC's CPU.
    So take you CPU and compare it to 222mhz.
    LUA can run at a max of 60 fps.

Posting Permissions

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