 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
newcoder
Joined: 22 Dec 2006 Posts: 10
|
Posted: Fri Dec 22, 2006 6:32 am Post subject: lua code help |
|
|
im new to lua but ive got a lot of the basics done. im wondering what is making my code just stay at a black screen and then reset i think it is the timer and if functions i have used but am not sure if someone could help that would be great. heres my code:
| Code: | red = Color.new(255,0,0)
background = Image.load("b.png")
player = Image.load("a.png")
jewel = Image.load("c.png")
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
Player = {}
Player[1] = {x=10,y=10}
Background = {}
Background[1] = {x=0,y=0}
Jewel = {}
Jewel[1] = {x=50,y=50}
Jewel[2] = {x=10,y=10}
Jewel[3] = {x=70,y=35}
Jewel[4] = {x=75,y=120}
Jewel[5] = {x=100,y=25}
counter = Timer.new()
counter:start()
while true do
pad = Controls.read()
screen:clear()
end
currentTime = counter:time()
screen:blit(Background[1].x, Background[1].y, background)
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
if currentTime > 100 then
screen:blit(Jewel[1].x,Jewel[1].y,jewel)
if currentTime > 250 then
screen:blit(Jewel[2].x,Jewel[2].y,jewel)
end
if currentTime > 400 then
screen:blit(Jewel[3].x,Jewel[3].y,jewel)
end
if currentTime > 550 then
screen:blit(Jewel[4].x,Jewel[4].y,jewel)
end
if currentTime > 700 then
screen:blit(Jewel[5].x,Jewel[5].y,jewel)
end
if currentTime > 1500 then
counter:reset(0)
counter:start()
end
screen.flip()
screen.waitVblankStart()
end
|
|
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Fri Dec 22, 2006 8:55 am Post subject: |
|
|
It gets stuck here:
| Code: | while true do
pad = Controls.read()
screen:clear()
end |
You put an end there where it shouldn't be. Now you close the while true do-loop and it just stays in it untill it crashes. You should remove it. |
|
| Back to top |
|
 |
newcoder
Joined: 22 Dec 2006 Posts: 10
|
Posted: Fri Dec 22, 2006 12:17 pm Post subject: |
|
|
| i tried tha against my better judgement and it gave me an error saying it has to have that "and". so any other suggestions? |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Fri Dec 22, 2006 4:38 pm Post subject: |
|
|
there is no such thing as "and"...
| Code: |
red = Color.new(255,0,0)
background = Image.load("b.png")
player = Image.load("a.png")
jewel = Image.load("c.png")
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
Player = {}
Player[1] = {x=10,y=10}
Background = {}
Background[1] = {x=0,y=0}
Jewel = {}
Jewel[1] = {x=50,y=50}
Jewel[2] = {x=10,y=10}
Jewel[3] = {x=70,y=35}
Jewel[4] = {x=75,y=120}
Jewel[5] = {x=100,y=25}
counter = Timer.new()
counter:start()
while true do
pad = Controls.read()
screen:clear()
currentTime = counter:time()
screen:blit(Background[1].x, Background[1].y, background)
screen:blit(Player[1].x,Player[1].y,player)
if pad:left() then if Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end end
if pad:right() then if Player[1].x < screenwidth then
Player[1].x = Player[1].x + 2
end end
if pad:up() then if Player[1].y > 0 then
Player[1].y = Player[1].y - 2
end end
if pad:down() then if Player[1].y < screenheight then
Player[1].y = Player[1].y + 2
end end
if currentTime > 100 then
screen:blit(Jewel[1].x,Jewel[1].y,jewel)
end
if currentTime > 250 then
screen:blit(Jewel[2].x,Jewel[2].y,jewel)
end
if currentTime > 400 then
screen:blit(Jewel[3].x,Jewel[3].y,jewel)
end
if currentTime > 550 then
screen:blit(Jewel[4].x,Jewel[4].y,jewel)
end
if currentTime > 700 then
screen:blit(Jewel[5].x,Jewel[5].y,jewel)
end
if currentTime > 1500 then
counter:reset(0)
counter:start()
end
screen.flip()
screen.waitVblankStart()
end
|
_________________ - be2003
blog |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Fri Dec 22, 2006 10:29 pm Post subject: |
|
|
| Well yeah ofcourse there should be an "end", but not in the place where you put it. The loop should close after all the other stuff you want it to do, so at the end of the code, like be2003 posted. |
|
| Back to top |
|
 |
|
|
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
|