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 

Menu skipping

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



Joined: 29 Sep 2005
Posts: 59

PostPosted: Tue Jan 10, 2006 4:08 pm    Post subject: Menu skipping Reply with quote

hey, i was just creating a basic menu for my game, and for some odd reason while on the first menu item, when i press down, it skips to the last menu item... there are 3 menu items total, here is my code for the up and down buttons.
Code:
if pad:down() then
      if hl1 == 1 then
        hl1 = 2
        screen.waitVblankStart(10)
      end
      if hl1 == 2 then
        hl1 = 3
        screen.waitVblankStart(10)
      end
    end
    if pad:up() then
      if hl1 == 2 then
        hl1 = 1
        screen.waitVblankStart(10)
      end
      if hl1 == 3 then
        hl1 = 2
        screen.waitVblankStart(10)
      end
    end

hl1 is tracking which menu item is currently selected. i'v tryed a few option to fixing this but maybe i need an outsider's view. its probably somthing simplle that i'm just not seeing.
Back to top
View user's profile Send private message AIM Address
Ferrero



Joined: 19 Dec 2005
Posts: 15

PostPosted: Tue Jan 10, 2006 6:31 pm    Post subject: Reply with quote

Hi,

I had the same problem with my menu to, but I found that when you hit a button, the event is raised many times (generaly 16 times) because of the speed of the loop of catching the events (each 1/60 ms).

So I've solved the problem with this code (my menu is a class) :

Code:
        if ((self.up==1)and(control:up()==false)) then
      self.selectedText = self.selectedText - 1;
      if (self.selectedText <= 0) then
         self.selectedText = 0;
      end
   end
   
   if ((self.down==1)and(control:down()==false))  then
      self.selectedText = self.selectedText + 1;
      if (self.selectedText >= self.nbText)  then
         self.selectedText = self.nbText-1;
      end
   end
   
   if (control:right()) then
      return self.selectedText;
   end
   
   if (control:up()) then
      self.up = 1;
   else
      self.up = 0;
   end
   
   if (control:down()) then
      self.down = 1;
   else
      self.down = 0;
   end
   
   return nil;


self.down and self.top are the states of the buttons.
selft.selectedText is the menu selected item

So, when you press the up button I put the button on, and when the button is pressed up, I change the selected menu line.

I've planned to manage a timer, to send a pressed up event when the user maintained the button pressed down while x ms
Back to top
View user's profile Send private message Visit poster's website
Slopey



Joined: 31 Jul 2005
Posts: 24

PostPosted: Tue Jan 10, 2006 10:08 pm    Post subject: Re: Menu skipping Reply with quote

Koba- your code is working correctly - if hl1 == 1 and you then set it to 2 then on the next if statement hl1 == 2 evaluates to true.

You'll need to use elseif rather than a new if statement ie:

Code:
if pad:down() then
      if hl1 == 1 then
        hl1 = 2
        screen.waitVblankStart(10)
      elseif hl1 == 2 then
        hl1 = 3
        screen.waitVblankStart(10)
      end
    end
    if pad:up() then
      if hl1 == 2 then
        hl1 = 1
        screen.waitVblankStart(10)
      elseif hl1 == 3 then
        hl1 = 2
        screen.waitVblankStart(10)
      end
    end



Would also be worth adding some code so the menu "wraps" round on itself (ie down from 3 goes to 1), and just increment the hl1 variable rather than assigning it directly

Code:

if pad:down() then
      hl1 = hl1 + 1
      if hl1 > 3 then
         hl1 = 1
      end
end
if pad:up() then
      hl1 = hl1 - 1
      if hl1 < 1 then
         hl1 = 3
      end
end
screen.waitVblankStart(10)
Back to top
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Tue Jan 10, 2006 10:17 pm    Post subject: Reply with quote

For an event driven Input system. (Does not toggle any repeats in input)
http://forums.ps2dev.org/viewtopic.php?t=4458

It can be located within the first page of the forum please learn to use the search engine.
Back to top
View user's profile Send private message
Koba



Joined: 29 Sep 2005
Posts: 59

PostPosted: Wed Jan 11, 2006 3:35 am    Post subject: Reply with quote

romero126 wrote:
For an event driven Input system. (Does not toggle any repeats in input)
http://forums.ps2dev.org/viewtopic.php?t=4458

It can be located within the first page of the forum please learn to use the search engine.

First of all, thank you very much you guys, for your help, and romero126, i use search before all my questions, and come up with absolutly nothing regarding to my topic. so sorry for bothering you, but apparently there ARE others on this board who are willing to help out a fellow programmer...
Back to top
View user's profile Send private message AIM Address
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Wed Jan 11, 2006 7:11 am    Post subject: Reply with quote

I was letting you know of a post not about a similar problem but about a fix with a library that was created to limit input presses to up and down functions only. Its not that Im trying to be negative towards new people but if the solution is within the grasp of somebody pushing them in the right direction is whats needed not repition of the same code over and over again. That is why the topic posted was within 4 spots away from the main board.

You just need to understand thats your problem which is why you where refrenced to that section vs me writing out the same code over and over again.

And in regards to the fellow programmer remark I find it fairly idiotic to take what I said as an insult to you as much as a clear statement on how to find the subject matter you are searching for. Fellow programmers dont write eachothers code regardless only offer simple solutions for common problems/mistakes.

Not trying to flame just giving you my thoughts on your comments.
Back to top
View user's profile Send private message
Koba



Joined: 29 Sep 2005
Posts: 59

PostPosted: Wed Jan 11, 2006 11:57 am    Post subject: Reply with quote

ok, i realize you were trying to help me, and not flame me, but did i ever once ask for someone to rewrite my code? all i needed from it was the elseif, one tiny code niplet... but anyways, i'll try even harder to find what i am looking for in the forums next time. oh and btw, when i said "thank you very much you guys" that included you too, i only singled you out on the next comment.

Last edited by Koba on Wed Jan 11, 2006 4:05 pm; edited 1 time in total
Back to top
View user's profile Send private message AIM Address
jimbo



Joined: 31 Mar 2005
Posts: 6
Location: Sunny Southern CA

PostPosted: Wed Jan 11, 2006 3:50 pm    Post subject: Reply with quote

Try these:
The splashscreen just displays an image until you hit start.
The menuscreen has some movable components: a solid backdrop over the image to provide contrast and a movable selection bar controlled by up/down under a layer of text on transparency. Saving the last state of controls allows it to wait for distinct button presses, rather than just the state which can still be depressed from a previous menu.
Code:

----------------------------------
-- Splash Screen
-- Just display an image until start is pressed
function splashScreen()
   splashimg = Image.load("backgrounds/background1.png")  -- 480 x 272
   while not Controls.read():cross() do
      screen:blit(0, 0, splashimg, 0, 0, splashimg:width(), splashimg:height(), false)
      screen.waitVblankStart()
      screen.flip()
   end
end

----------------------------------
-- Menu Screen
-- Display a menu of different options selectable using controls
-- Returns the index of the selected option
-- Possible parameters:
--   background image
--   number of parameters
--   names of parameters
function menuScreen()
   local numoptions  = 2
   local optionnames = {}
   optionnames[1] = "Execute"
   optionnames[2] = "Edit Mode"

   local bgoffx      = 100
   local bgoffy      = 80
   local baroffx     = 30
   local baroffy     = 20
   local baroffskip  = 30
   local optiontxtoffx = 5
   local optiontxtoffy = 5

   -- imaging
   local green1      = Color.new(0, 64, 0)
   local optionbgcol = Color.new(64, 64, 64)
   local optionfgcol = Color.new(255,255,255)
   local splashimg   = Image.load("backgrounds/background2.png")
   local selectbar   = Image.createEmpty(100,20)
   local optionbg    = Image.createEmpty(200,100)
   local optiontxt   = Image.createEmpty(200,100)

   -- paint components colors to their images
   optionbg:fillRect(0, 0, optionbg:width(),optionbg:height(), optionbgcol)
   selectbar:fillRect(0, 0, selectbar:width(),selectbar:height(), green1)
   -- Paint Menu Options to a clear image
   for i =   1, numoptions do
      optiontxt:print(baroffx + optiontxtoffx, baroffy + baroffskip*(i-1) + optiontxtoffy,  optionnames[i], optionfgcol)
   end

   -- add offsets for moving selection bar
   local baroffx     = baroffx + bgoffx
   local baroffy     = baroffy + bgoffy

   -- State variables
   local selopt     = 0
   local keep_going = true
   local menuPush   = Controls.read() -- state of controls
   local LastPush   = menuPush
   while keep_going do
      LastPush = menuPush
      menuPush = Controls.read()

      if menuPush:up()    and not LastPush:up()    then  selopt = math.mod( selopt - 1 + numoptions, numoptions)  end
      if menuPush:down()  and not LastPush:down()  then  selopt = math.mod( selopt + 1 + numoptions, numoptions)  end
      if menuPush:cross() and not LastPush:cross() then  keep_going = false                                       end

      screen:blit(0, 0, splashimg, 0, 0, splashimg:width(), splashimg:height(), false)
      -- draw option selector bar under text
      screen:blit(bgoffx, bgoffy, optionbg, 0, 0, optionbg:width(),optionbg:height(), true)
      screen:blit(baroffx, baroffy + selopt * baroffskip, selectbar, 0, 0, selectbar:width(),selectbar:height(), true)
      -- draw option text layer
      screen:blit(bgoffx, bgoffy, optiontxt, 0, 0, optiontxt:width(),optiontxt:height(), true)

      screen.waitVblankStart()
      screen.flip()
   end
   return selopt
end

Back to top
View user's profile Send private message Visit poster's website AIM Address
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