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 

Coding Help with buttons

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



Joined: 23 Aug 2005
Posts: 5

PostPosted: Tue Aug 23, 2005 1:45 pm    Post subject: Coding Help with buttons Reply with quote

I'm trying to run a simple program that is mostly text based. I started off by loading a simple image in the background and checking to see if I could get text up (with the simple Hello World). I got that to work, but then I wanted to add a button function to let the user advance to more text.

I got that to work as well, however, you had to hold the button down to view the text or else it goes back to the old text.

I reworked things around and tried something else by calling a function.

Now I get this error message:

error: script.lua:39: <eof> expected near 'end'

Here's my code:

Code:

-- load images
background = Image.load ("image.png")

-- create a new Color object
green = Color.new(0, 255, 0)
while true do
   screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)

-- show some text on offscreen
screen:print(200, 100, "Hello World!", green)
end
   
-- function
function option2()
while true do
   screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
-- show some text on offscreen
screen:print(200, 100, "Hello World!oneone!", green)
end

   
   
-- controls
   Pad = Controls.read()
   if Pad:cross() or Pad:start() then
      screen.waitVblankStart(1)
      return "option2"
      end
   end
-- flip visible and offscreen
screen.flip()

      

-- wait forevever
   screen.waitVblankStart()


end

Back to top
View user's profile Send private message Visit poster's website AIM Address
Benihana



Joined: 31 Jul 2005
Posts: 12

PostPosted: Tue Aug 23, 2005 2:30 pm    Post subject: Reply with quote

Lua doesn't mean what it says half the time - and that's not really Lua's fault. It would be near impossible for it to know what you mean when you make a mistake.

If this is your only code, you have an extra end... therefore my guess is that is what is causing your issues. Since I am not at home I can't check for you. Another easy mistake is misspellings, but I couldn't find any of those. A Lua IDE would likely catch such a mistake, as it would highlight the extra end, or throw off indenting. Also it would be useful to mark line 39 so that regardless of formatting everyone else knows what line is causing the error.

As far as buttons, although many people preach against global variables, I recommend it in this case. You can use a variable set to true or false, like buttonDown == true when the button is down. Sometimes I get lost trying to pass variables back and forth between functions.
Back to top
View user's profile Send private message
MikeHaggar



Joined: 18 Jul 2005
Posts: 116

PostPosted: Tue Aug 23, 2005 10:23 pm    Post subject: Reply with quote

Dunno if this is what you want:

Code:

-- load images
background = Image.load ("image.png")

-- function
function option2()
  while true do
    screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
    -- show some text on offscreen
    screen:print(200, 100, "Hello World!oneone!", green)
  end
end


-- create a new Color object
green = Color.new(0, 255, 0)

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

  -- show some text on offscreen
  screen:print(200, 100, "Hello World!", green)

  -- controls
  Pad = Controls.read()
  if Pad:cross() or Pad:start() then
    screen.waitVblankStart(1)
    return "option2"
  end

  -- flip visible and offscreen
  screen.flip()

  -- wait forevever
  screen.waitVblankStart()

end
Back to top
View user's profile Send private message
Barcode



Joined: 23 Aug 2005
Posts: 5

PostPosted: Wed Aug 24, 2005 2:16 am    Post subject: Reply with quote

I tried that, but when you press X, the screen goes blank and says "press start to restart" with nothing to show my error.

I'm wanting to make a game that is pretty much text based.

Typically, i want to show a background image and have some kind of text saying "Hit X to continue". When you press X, it will apply a different background and then new text. Then hit X again to continue. Eventually the controls will become more complex to where you have options as to what you want happen. Typically, I'm working on a simple simdate game.
Back to top
View user's profile Send private message Visit poster's website AIM Address
mikeyleo



Joined: 21 Jul 2005
Posts: 6

PostPosted: Wed Aug 24, 2005 3:34 am    Post subject: Reply with quote

Should the line return "Option2" be there? Is in the main loop. I think when you execute that line you would exit.
Back to top
View user's profile Send private message
Arwin



Joined: 12 Jul 2005
Posts: 426

PostPosted: Wed Aug 24, 2005 5:15 am    Post subject: Reply with quote

reading the controller is non-blocking, in Lua too. If I understood it correctly anyway. So that means you read the buttons, and then the program just goes on, no matter what is being read.

I'm not at all versed in Lua yet, but I assume that if you want to wait until X is pressed, you do something like

while not Pad:cross() do
Pad = Controls.read()
end

This should wait for a key to be pressed. Put this in your main loop, and move on to the next screen as soon as you've exited that loop.
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Wed Aug 24, 2005 5:22 am    Post subject: Reply with quote

Code:
   
continue = false
repeat   --wait till x is pressed!
   pad = Controls.read()
   if pad:cross() then
      continue=true
      screen.waitVblankStart(30) -- 1/2 sec
   end
until continue==true

set the wait time to whatever you want, i set it to half a sec
greets
Back to top
View user's profile Send private message Visit poster's website
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