strange table.. or is it just me?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
liquid8d
Posts: 66
Joined: Thu Jun 30, 2005 6:29 am

strange table.. or is it just me?

Post by liquid8d »

Not quite sure what is going on here.. I have looked over the lua tutorials on tables, and it seems to me like this should work, so here goes:

Code: Select all


keypadloc = {x = 0, y = 0}
locTopRight = {x = 330, y = 10}
locTopLeft = {x = 10, y = 10} 
locBottomRight = {x = 330, y = 122}
locBottomLeft = {x = 10, y = 122}

keypad = Image.load("pad.png")

function drawPad()
 screen:blit(keypadloc.x,keypadloc.y,keypad)
end


while true do
   pad = Controls.read()
   screen:clear()
   screen:blit(0,0,bg,false)
   if (pad ~= oldPad) then
      if pad:start() then
         break
      end

      if pad:l() then

         if (keypadloc == locTopLeft) then
            keypadloc = locTopRight
         elseif (keypadloc == locTopRight) then
            keypadloc = BottomRight
         elseif (keypadloc == locBottomRight) then
            keypadloc = locBottomLeft
         else
            keypadloc = locTopLeft
         end

      end

      oldPad = pad
   end
   
   if (showpad == true) then
     drawPad()
   end
   
   screen:waitVblankStart(10)
   screen:flip()
end


It seems to me that this should work, but what happens is, after I have set the keypadloc to each location, when you set it to one of the locations a second time, it says 'attempt to index global 'keypadloc' (a nil value). Why is it nil all of the sudden? Do you have to copy a table, and not set it equal to? Am I just doing something wrong?

Thanks,

LiQuiD8d
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

BottomRight is undefined.
liquid8d
Posts: 66
Joined: Thu Jun 30, 2005 6:29 am

Post by liquid8d »

son of a %@#% .. I don't know how you guys continue to answer everyones questions, including stupid ones like that, and continue to work on your project :) Keep it up :)

MY BAD.

LiQuiD8d
Post Reply