Help with screen:blit...

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

Moderators: Shine, Insert_witty_name

Post Reply
Cybojanek
Posts: 1
Joined: Tue May 16, 2006 12:43 pm

Help with screen:blit...

Post by Cybojanek »

Hi,
I recenley started coding and I recieve an error when I run my code. ( on my PC). It states "Bad argument #2 to 'blit' <image expected, got table>
Here is my code. If you could pleases help me fix it I would be very grateful....
THNX :)

arrow = Image.load("arrow.png")
grass = Image.load("grass.png")

screenwidth = 480 - arrow:width()
screenheight = 272 - arrow:width()

arrow = {}
arrow[1] = { x = 200, y = 50}

--***** Main Loop *****
while true do
pad = Controls.read()
screen:clear()

for a = 0, 14 do
for b = 0,8 do
screen:blit(32 * a, 32 * b, grass)
end
end

screen:blit(300,220,arrow)

if pad:left() and arrow[1].x > 0 then
arrow[1].x = arrow[1].x - 2
end

if pad:right() and arrow[1].x < screenwidth then
arrow[1].x = arrow[1].x + 2
end

if pad:up() and arrow[1].y > 0 then
arrow[1].y = arrow[1].y - 2
end

if pad:down() and arrow[1].y < screenheight then
arrow[1].y = arrow[1].y + 2
end

screen.waitVblankStart()
screen.flip()
end
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

Code: Select all

arrow = Image.load&#40;"arrow.png"&#41;
grass = Image.load&#40;"grass.png"&#41;

screenwidth = 480 - arrow&#58;width&#40;&#41;
screenheight = 272 - arrow&#58;width&#40;&#41;

arrow = &#123;&#125;
arrow&#91;1&#93; = &#123; x = 200, y = 50&#125;
...
 
You had defined 'arrow' variable twice. The first definition was an image and the second was a table. That's why you got an error.
Geo Massar
Retired Engineer
Gary13579
Posts: 93
Joined: Mon Aug 15, 2005 7:43 am

Post by Gary13579 »

Ack, you beat me too it. I had my post done with color coding and everything :(
User avatar
daurnimator
Posts: 38
Joined: Sun Dec 11, 2005 8:36 pm
Location: melbourne, australia

Post by daurnimator »

your all too quick for me :S
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

daurnimator wrote:Ack, you beat me too it. I had my post done with color coding and everything :(
Why don't you just post your colorful reply, anyway? We all are curious to see yours.
Geo Massar
Retired Engineer
Gary13579
Posts: 93
Joined: Mon Aug 15, 2005 7:43 am

Re: Help with screen:blit...

Post by Gary13579 »

arrow = Image.load("arrow.png")
grass = Image.load("grass.png")

screenwidth = 480 - arrow:width()
screenheight = 272 - arrow:width()

arrow = {}
arrow[1] = { x = 200, y = 50}

--***** Main Loop *****
while true do
pad = Controls.read()
screen:clear()

for a = 0, 14 do
for b = 0,8 do
screen:blit(32 * a, 32 * b, grass)
end
end

screen:blit(300,220,arrow)

if pad:left() and arrow[1].x > 0 then
arrow[1].x = arrow[1].x - 2
end

if pad:right() and arrow[1].x < screenwidth then
arrow[1].x = arrow[1].x + 2
end

if pad:up() and arrow[1].y > 0 then
arrow[1].y = arrow[1].y - 2
end

if pad:down() and arrow[1].y < screenheight then
arrow[1].y = arrow[1].y + 2
end

screen.waitVblankStart()
screen.flip()
end


Pretty much just replace the blue words with "arrowImg".

BTW, you screwed your quote tag up. It says daurnimator wrote that, when it was me..
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

Sorry, dude!

BTW, nice looking, indeed. :)
Geo Massar
Retired Engineer
Post Reply