User Control Panel
Advertisements

HELP US, HELP YOU!

more snails

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
draget
Not Yet a God
Not Yet a God


Joined: 29 Dec 2004
Posts: 367
Location: Australia
Reputation: 32.2Reputation: 32.2Reputation: 32.2

PostPosted: Tue Apr 12, 2005 12:42 pm    Post subject: Reply with quote

i decided to re-write snailz, in order for it too work better.


While loop:
Code:
<br /><br />foreach my $sock (keys %{$active}) {<br />     <br />my $self = $msn->getConvo ($sock);<br /><br /><br />if(exists $self->{snailz}->{race}){<br /><br />if(length(@race) != 0) {<br /><br /><br /><br />my @race = $self->{snailz}->{race};<br /><br />&send($self, @race[0], $username);<br /><br />shift @race;<br /><br />$self->{snailz}->{race} = @race;<br /><br />}<br /><br />else {<br /><br /><br /><br />   &send($self,"GONE! Race over. Snail $self->{snailz}->{winner} won the race.",$username);   <br /><br />delete $self->{snailz}->{race};<br />delete $self->{snailz}->{winner};<br /><br />}<br /><br /><br /><br /><br />}<br /><br /><br /><br />}




snailz.maya:
Code:
my $i = 1;<br />my %members = $self->getMembers();<br />  my $list = "";<br />  foreach my $member2 (keys %{$members}) {<br />     <br />   $list .= "Snail $i = $member2\n"; $i++;<br /><br />  }   <br />   <br /><br />&send($self,$list,$username);<br /><br />$msn->do_one_loop(); <br /><br />   $snails = [];<br />push(@$snails, 0) for(keys %{$self->{Members}});<br /><br />   &send($self,"Starting The Race....\n",$username); sleep(2);<br /><br />my @race;<br />my $winner = undef;<br /><br />   while (not $winner) {  #while there is no winner<br />       my $snail = int rand $i; #pick a snail<br />       $snails->[$snail]++;  # move it<br />       $winner = $snail + 1 if ($snails->[$snail] >= 30); # did it win?<br />       $msn->do_one_loop();  #give other stuff a chance<br />       @race = (@race, "going ....\n" . showsnails($snails) );<br />   }<br />   <br /><br />$self->{snailz}->{race} = @race;<br />$self->{snailz}->{winner} = $winner;<br /><br /><br />   <br /><br />sub showsnails {<br />   my $snails = shift;<br />   my $reply = "";<br />   my $i = 1;<br />   foreach my $snail (@$snails)<br />   {<br />       $reply .= $i++ . " " . "- " x $snail . "(sn)" . "- " x (30 - $snail) . "\n";<br />   }<br />   return $reply;<br />}



My problem is such: when it gets to sending the race through the loop it first sends '56' then gets stuck in a infinite loop sending '0'. :huh:

I think it may have something to do with how i have used the hash to get from the command to the loop, thought i could work, can anyone suggest why this is happening and a way that it would work?


Thanks, draget
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group