Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
icedsun
Novice


Joined: 20 Jan 2006
Posts: 45
Location: Minnesota

PostPosted: Sun Feb 05, 2006 5:39 am   

Is this a bug?
 
Okay, I've got a bug and cannot determine what's causing it. This alias should work fine, but for some reason it doesn't.

The only problem with it is that the LOOP that starts right after Poker.WhoWon is doing something funky. As soon as I enter the LOOP statement, there's an IF statement that wants to make sure of two things:
First: Are they out of chips?
Second: Is there actually a person there.
Hence: #IF (@TheirChips<=0 AND @TheirName)
Usually I use an IF statement with a variable inside it like @TheirName and if @TheirName contains ANYTHING Non-0, that should make that part of the IF statement true. ANYHOW, this #IF statement is finding itself firing EVERY TIME. Even when the player has any number of chips, 0 chips, etc. I added the #SHOW command right before it does the IF statement to debug and make sure that the variables weren't being read wrong or something. The IF statement still fires even when @TheirChips is any number and regardless of @TheirName. I also found that if I change it to #IF (@TheirChips<=0 AND @TheirName="Monkey") then the trigger finally is smart enough NOT to fire unless the conditions are correct. (ie... theirchips is 0 or less, and their name was "Monkey") What am I doing wrong :) If you guys need any explanation of what something else in the script does, just ask.

Code:
#VAR Counter "" _nodef PokerTemp
#VAR Pots 0 _nodef PokerTemp
#VAR PotIn @HandIn _nodef PokerTemp
#VAR Losers "" _nodef PokerTemp
#LOOP 1,10 {
  #VAR Counter %i _nodef PokerTemp
  #VAR PotSmallest 999999999999 _nodef PokerTemp
  #VAR PotElig%i "" _nodef PokerVars
  #VAR PotAmt%i 0 _nodef PokerVars
  #LOOP 1,%numitems(@PotIn) {
    #VAR tmp @{ChipsInTotal%item(@PotIn,%j)} _nodef PokerTemp
    #IF (@tmp<@PotSmallest AND @tmp>0) {#VAR PotSmallest @tmp _nodef PokerTemp}
    }
  #VAR PotElig@Counter @PotIn _nodef PokerVars
  #IF (@PotSmallest!=999999999999) {
    #LOOP 1,%numitems(@{PotElig@Counter}) {
      #ADD PotAmt@Counter @PotSmallest
      #VAR tmp %item(@{PotElig@Counter},%j) _nodef PokerTemp
      #ADD ChipsInTotal@tmp -@PotSmallest
      #IF (@{ChipsInTotal@tmp}<=0) {#DELITEM PotIn @tmp}
      }
    }
  #IF (%numitems(@{PotElig@Counter})) {#ADD Pots 1}
  }
Poker.WhoWon
#LOOP 1,%numitems(@StillIn) {
  #VAR TheirChips @{Chips%item(@StillIn,%i)} _nodef PokerTemp
  #VAR TheirName @{Seat%item(@StillIn,%i)} _nodef PokerTemp
  #SHOW Their Chips~: @TheirChips Their Name~: @TheirName
  #IF (@TheirChips<=0 AND @TheirName) {
    #VAR LostPlace %eval(%numitems(@StillIn)-%numitems(@Losers)) _nodef PokerTemp
    Poker.Inform.Loser %item(@StillIn,%i) @LostPlace
    #VAR Account@{Seat%item(@StillIn,%i)}.Finished %additem(%numitems(@StillIn),@{Account@{Seat%item(@StillIn,%i)}.Finished}) _nodef Accounts
    #VAR Account@{Seat%item(@StillIn,%i)}.FinWeighted %additem(%eval(1000*%numitems(@StillIn)/%numitems(@Registered)),@{Account@{Seat%item(@StillIn,%i)}.FinWeighted}) _nodef Accounts
    #VAR tmp 0 _nodef PokerTemp
    #FORALL @{Account@{Seat%item(@StillIn,%i)}.FinWeighted} {#ADD tmp %j}
    #VAR tmp %eval(@tmp/%numitems(@{Account@{Seat%item(@StillIn,%i)}.FinWeighted})) _nodef PokerTemp
    #IF (@tmp<@AALeader.GamesWeight) {
      #VAR AALeader.GamesWeight @tmp _nodef Accounts
      #VAR AALeader.GamesPerson @{Seat%item(@StillIn,%i)} _nodef Accounts
      Poker.Inform.NewGamesLeader
      }
    #ADDITEM Losers %item(@StillIn,%i)
    }
  }
#FORALL (@Losers) {#DELITEM StillIn %j}
#VAR tmp "" _nodef PokerTemp
#LOOP 1,%numitems(@HandIn) {
  #ADDITEM tmp %item(@HandIn,%i)
  #ADDITEM tmp %replace(@{Cards%item(@HandIn,%i)},"~|","~-")
  }
#WRITE 1 {%time( ddddd tt) ~*~*~*~*~*~*~*~*~*~* Hand ~#@HandNum Done~. Community~: @FlopA @FlopB @FlopC @Turn @River PCards~: %expandlist(@tmp," ")}
Poker.StatusChange 3
#ALARM "HandTimer" {@HandWait} {Poker.NextHand} PokerTimers
_________________
"Build a man a fire and he's warm for a night. Light a man on fire and he's warm for the rest of his life." --My Mom
Reply with quote
Vodoc
Apprentice


Joined: 11 Apr 2003
Posts: 119
Location: Sweden

PostPosted: Sun Feb 05, 2006 9:04 am   
 
I'm not yet fully awake and didn't really care to read all your post but this struck to me immediately.
icedsun wrote:
#VAR PotSmallest 999999999999 _nodef PokerTemp

Isn’t that going to overflow? I don't remember what the highest available number is but yours seems to be awfully big.
Reply with quote
Slaem
Apprentice


Joined: 20 Sep 2005
Posts: 135

PostPosted: Sun Feb 05, 2006 10:31 am   
 
2,147,483,647 is the highest integer.

Vijilante comments on this and provides a workaround here (Lightbulb explains the limit also):
Vijilante wrote:
zMud treats all variables as strings ... The limit for 32 bit numbers is only encountered when the string is converted to a number for math functions.
_________________
Show your love.
Support Zugg Software!
Donate to zugg@zuggsoft.com with PayPal Send Money.
Reply with quote
icedsun
Novice


Joined: 20 Jan 2006
Posts: 45
Location: Minnesota

PostPosted: Mon Feb 06, 2006 9:00 am   
 
The highest integer bug is duly noted, but luckily it doesn't really affect this function. The PotSmallest var always changes right away to a number less than the 9999999999 that it was set to. I did try lowering it's initial setting to 1,000,000,000 just to make sure it wasn't overflowing and causing trouble later. It didn't fix the problem though...
_________________
"Build a man a fire and he's warm for a night. Light a man on fire and he's warm for the rest of his life." --My Mom
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Feb 06, 2006 11:24 pm   
 
If I am right this is the line you say is causing a problem.
#IF (@TheirChips<=0 AND @TheirName) {

While it should not really necessary, I find it best to always explicitly control the order of operations in logical evaluations. I apply this to every language, since anyone reading my code years from now will be able to understand exactly what I wanted.
#IF ((@TheirChips<=0) AND (@TheirName)) {
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
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

© 2009 Zugg Software. Hosted by Wolfpaw.net