Team XSaturn's Forum Site
 
HomeHome  ­GalleryGallery  ­FAQFAQ  ­SearchSearch  ­MemberlistMemberlist  ­UsergroupsUsergroups  ­RegisterRegister  ­Log inLog in  
Post new topic   Reply to topicShare | 
 

 Help with directional input

View previous topic View next topic Go down 
AuthorMessage
AquaClouds



Posts: 8
Join date: 2008-07-17

PostSubject: Help with directional input   Thu Jul 17, 2008 6:32 am

I get an error whenever I try pressing any directional button. The error says "loop in gettable"
Here is my code:
Code:
cursor=Image.load("cursor.png")

while true do
pad = Controls.read()
screen:clear()

screen:blit(0,0,cursor)

if pad:left() then
cursor.x = cursor.x-10
end

if pad:right() then
cursor.x = cursor.x+10
end

if pad:up() then
cursor.y = cursor.y-10
end

if pad:down() then
cursor.y = cursor.y+10
end

screen.waitVblankStart()
screen.flip()
end


Thanks in advance for the help!
Back to top Go down
View user profile Http://theblueskywind.homeip.net
Tdude_gamer
Admin


Posts: 6
Join date: 2008-07-16
Location: Hawaii

PostSubject: Re: Help with directional input   Thu Jul 17, 2008 6:45 am

you don't have an array for the cursor and you need to blit the variable cursor.x and cursor.y, not as 0, cause the variable is stored as cursor.x, not 0. and use functions, it will clean up your code. use this exact code:

Code:
red = Color.new(255,0,0)

cursor = {x = 0, y = 0, img = Image.createEmpty(32,32)}
cursor.img:clear(red)

function controls()
  if pad:up() then
      cursor.y = cursor.y + 3
  end
 
  if pad:down() then
      cursor.x = cursor.x - 3
  end

  if pad:left() then
      cursor.x = cursor.x + 3
  end
 
  if pad:right() then
      cursor.x = cursor.x - 3
  end
end

while true do
screen:clear()
pad = Controls.read()

controls()

screen:blit(cursor.x,cursor.y,cursor.img)

screen.waitVblankStart()
screen.flip()
end


Last edited by Tdude_gamer on Sun Aug 03, 2008 7:31 am; edited 1 time in total
Back to top Go down
View user profile http://teamxsaturn.my5gb.com/
AquaClouds



Posts: 8
Join date: 2008-07-17

PostSubject: Thanks!   Thu Jul 17, 2008 9:07 am

Okay, I think I understand better now, thanks for the help.
Now I've just gotta work on only moving it upon the "release" of the directional keys.

EDIT: After reviewing the tutorials, I understand how it works now. I tried to increase/decrease a variable that I had not defined yet. Thanks again for the help!

Your code had only one line that contained an error and if anyone else would like to use the code I'm going to post the correct changes:
From this:
Code:

  if pad:down() then
      cursor.x = cursor.x - 3
  end

To this:
Code:

 if pad:down() then
      cursor.y = cursor.y + 3
  end
Back to top Go down
View user profile Http://theblueskywind.homeip.net
Tdude_gamer
Admin


Posts: 6
Join date: 2008-07-16
Location: Hawaii

PostSubject: Re: Help with directional input   Sun Aug 03, 2008 7:30 am

sorry, for the error, i guess i was kind of careless when i typed that. i will edit the code on my post. and it should be:
Code:

  if pad:up() then
      cursor.y = cursor.y + 3
  end

not:
Code:

  if pad:down() then
      cursor.y = cursor.y + 3
  end
Back to top Go down
View user profile http://teamxsaturn.my5gb.com/
 

Help with directional input

View previous topic View next topic Back to top 
Page 1 of 1

Permissions of this forum:You cannot reply to topics in this forum
Team XSaturn :: PSP :: Coding Help-
Post new topic   Reply to topic