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 

Problem with elseif block

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



Joined: 24 Jun 2005
Posts: 7
Location: Canada

PostPosted: Wed Jan 11, 2006 3:45 pm    Post subject: Problem with elseif block Reply with quote

Hi, I am working on a poker type of game, and I have this section with a list of "elseifs":

Code:
function findBestHand()

   hand_type = NOTHING
   str = "nothing"

   -- Search in this order

   if isRoyalFlush() == 1 then
      hand_type = ROYAL_FLUSH
      str = "Royal Flush"

   elseif isStraightFlush() == 1 then
      hand_type = STRAIGHT_FLUSH
      str = "Straight Flush"

   elseif isFourOfKind() == 1 then
      hand_type = FOUR_KIND
      str = "Four of a Kind"

   elseif isFullHouse() == 1 then
      hand_type = FULL_HOUSE
      str = "Full House"

   elseif isFlush() == 1 then
      hand_type = FLUSH
      str = "Flush"

   elseif isStraight() == 1 then
      hand_type = STRAIGHT
      str = "Straight"

   elseif isThreeOfKind() == 1 then
      hand_type = THREE_KIND
      str = "Three of a Kind"

   elseif isTwoPairs() == 1 then
      hand_type = TWO_PAIRS
           str = "Two Pairs"
      
   elseif isOnePair() == 1 then
      hand_type = ONE_PAIR
      str = "One Pair"

   else
      hand_type = getHighCard()
      str = "High Card: " .. hand_type
   end
   
   y = 25 + card_back:height()
   screen:print(5, y, "You got " .. str, white)

   screen.waitVblankStart()
   screen:flip()

   return hand_type

end -- findBestHand


I've only finished the functions called isTwoPairs(), isOnePair(), and getHighCard(). The rest are just stubs.

The problem is, when I run this function on my PSP, it appears that whenever I have two pairs in my hand, it prints "You got Two Pairs"; but then, ON TOP of that string, it also overlaps it with "You got One Pair"! So it seems like when the Two Pair condition is met, it still checks the next condition, which is One Pair (which would also be met), and then prints both of them!

When I don't have two pairs, but have one pair instead, it correctly prints the One Pair string only. Likewise, when I don't have a single pair, it prints the High Card string only.

Any idea what I may have done wrong in the two pair case??
Back to top
View user's profile Send private message
dandev



Joined: 24 Jun 2005
Posts: 7
Location: Canada

PostPosted: Wed Jan 11, 2006 4:00 pm    Post subject: Reply with quote

Oops, sorry.. I figured it out. I forgot to clear some flags, so whenever it looped over to this function again it stopped satisfying the two pair case.

My apologies.. you can delete this post.
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