forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

collision help

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
newcoder



Joined: 22 Dec 2006
Posts: 10

PostPosted: Tue Feb 20, 2007 12:47 am    Post subject: collision help Reply with quote

i keep getting errors and i know its probably something small so could someone just check my code so that i can get done with the collision. (im terrible at collision).
heres my code:

Code:
System.usbDiskModeActivate()

red = Color.new(225,0,0)
player = Image.load("player.png")
background = Image.load("background.png")
pic1 = Image.load("pic1.png")
pic2 = Image.load("pic2.png")
Pic = { }
Pic[1] = { x= 80, y = 95, height = pic1:height(), width = pic1:width() }
Player = { }
Player[1] = { x = 50, y = 107 }
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
playerHeight = 90
playerWidth = 90
function collisionCheck(Pic)
if (Player[1].x + playerWidth > Pic[1].x) and (Player[1].x < Pic[1].x + Pic[1].width) and (Player[1].y + playerHeight > Pic[1].y) and (Player[1].y < Pic[1].y + Pic[1].height) then
Player[1].x = oldx
Player[1].y = oldy
end
end
function movePlayer()
pad = Controls.read()
if pad:left() then
Player[1].x = Player[1].x - 1
end
if pad:right() then
Player[1].x = Player[1].x + 1
end
if pad:up() then
Player[1].y = Player[1].y - 1
end
if pad:down() then
Player[1].y = Player[1].y + 1
end
end
while true do
pad = Controls.read()
oldx = Player[1].x
oldy = Player[1].y
screen:clear()
collisionCheck(Pic[1])
screen:blit(0,0,background)
screen:blit(Pic[1].x,Pic1.y,pic1)
screen:blit(140,107,pic2)
screen:blit(Player[1].x,Player[1].y,player)
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end

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

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

if pad:down() and Player[1].y < screenheight then
Player[1].y = Player[1].y + 2
end
screen.waitVblankStart()
screen.flip()
end

everything worked up until i implemented collision so i know its something with that.
i you want to know the actual error it says:
attempt to index global field '?' a nil value
Back to top
View user's profile Send private message
Altair



Joined: 20 May 2006
Posts: 76
Location: The Netherlands

PostPosted: Tue Feb 20, 2007 2:08 am    Post subject: Reply with quote

What line is the error on?
Back to top
View user's profile Send private message
newcoder



Joined: 22 Dec 2006
Posts: 10

PostPosted: Tue Feb 20, 2007 2:09 am    Post subject: Reply with quote

i think 15
Back to top
View user's profile Send private message
newcoder



Joined: 22 Dec 2006
Posts: 10

PostPosted: Tue Feb 20, 2007 9:12 am    Post subject: Reply with quote

anyone??
Back to top
View user's profile Send private message
harleyg



Joined: 05 Oct 2005
Posts: 123

PostPosted: Tue Feb 20, 2007 11:27 am    Post subject: Reply with quote

1. "i think 15" is not a definite answer.
2. Learn to wait on these forums, do not expect answer straight away.
Back to top
View user's profile Send private message
newcoder



Joined: 22 Dec 2006
Posts: 10

PostPosted: Tue Feb 20, 2007 11:57 am    Post subject: Reply with quote

i know its just everytime i get to collision i end up dropping the project cause i cant get it to work. ill be more patient
Back to top
View user's profile Send private message
Altair



Joined: 20 May 2006
Posts: 76
Location: The Netherlands

PostPosted: Wed Feb 21, 2007 4:46 am    Post subject: Reply with quote

Nope it cant be 15. Just run the game and see what the error says, complete with line number and post it here. Maybe then we can help you
Back to top
View user's profile Send private message
newcoder



Joined: 22 Dec 2006
Posts: 10

PostPosted: Wed Feb 21, 2007 8:37 am    Post subject: Reply with quote

the error says this:
error: script.lua:15: attempt to index field '?' (a nil value)
Back to top
View user's profile Send private message
Altair



Joined: 20 May 2006
Posts: 76
Location: The Netherlands

PostPosted: Sat Feb 24, 2007 11:06 pm    Post subject: Reply with quote

And this is all of your code? That would mean it would be this line:

Code:
playerWidth = 90


Right?

I don't see anything wrong with that.
Back to top
View user's profile Send private message
Kleptoone



Joined: 02 Mar 2007
Posts: 2

PostPosted: Fri Mar 02, 2007 8:20 am    Post subject: Its the variable your passing into the collision function Reply with quote

You're passing the specific index into the function and trying to index it again. you pass Pic[1] and then are trying to test Pic[1][1]. just pass the array without the one and it should work (at least compile)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group