PDA

View Full Version : Lua* help Edit ****



jason215
August 30th, 2006, 10:28
hi,

if got some problems whith my lua script
(dont get angry because im a bit noob with lua)

but if somebody can look at it thnx i appriciatet it
*srry 4 my bad english :(


anyways i'm always getting this error

error: index.lua:81: bad argument #2 to 'blit' (image expected, got table)

here's the code

-- images
background=Image.load("back.jpg")
player1 = Image.load("Naruto.png")
shadow = Image.load("shadow.png")

-- player 1

player={}
player.gravity = 200
player.x = 50
player.y = 250
player.jumpspeed = 10
player.jumpstate = "ground"

-- player 2

shadow={}
shadow.x = 30
shadow.y = 230


-- controls

function controls()
pad=Controls.read()
end

while true do
controls()
screen:blit(0,0,background,false)


controls()
if pad:right()then
player.x = player.x + 4
shadow.x = shadow.x + 4
end

if pad:left()then
player.x = player.x - 4
shadow.x = shadow.x - 4
end


-- jumping script

if pad:cross() and player.jumpstate == "ground" then player.jumpstate = "jumping"

end

if player.jumpstate == "jumping"
then player.jumpspeed = player.jumpspeed - 0.5
player.gravity = player.gravity - player.jumpspeed

end

if player.gravity < 0 then
player.jumpstate = "falling"

end

if player.gravity < 200 and player.jumpstate == "falling" then player.gravity = player.gravity + (player.jumpspeed + 3)

end

if player.gravity == 200 then
player.jumpspeed = 10
player.jumpstate = "ground"
end

if player.gravity > 200 then player.gravity = 200

end

player.y = player.gravity

--end jumpscript

-- Shadow Replication Script

screen:blit(shadow.x,shadow.y,shadow)


-- End Shadow script

screen:blit(player.x,player.y,player1)

screen.waitVblankStart()
screen.flip()
end

yaustar
August 30th, 2006, 11:01
Here is your problem:
You use the shadow variable as an image here:
shadow = Image.load("shadow.png")

but you change it to a table here:
shadow={}
shadow.x = 30
shadow.y = 230

So in the blit command you are passing it a table which is bringing up the error.

jason215
August 30th, 2006, 11:08
thnx man :) :) :D :D

jason215
August 30th, 2006, 11:22
srry but why isnt this working if i press up nothing appears ... :( if someone can help again :) thnx



-- Shadow Replication Script
if pad:up() and player.jumpstate == "ground" then
screen:blit(shadow.x,shadow.y,shadow1)

yaustar
August 30th, 2006, 12:26
Looks fine. Nothing wrong with those 2 lines of code.