Joined: 06 Jan 2004 Posts: 93 Location: Nottinghamshire, UK votes: 4
Posted: Thu Mar 04, 2004 8:34 pm Post subject:
im a bit of a n00b to andromeda callbacks, i cant honestly see anything wrong with this command but apparently there is (btw i had a go at indenting, soz if its wrong)
Code:
sub snails {<br /> my ($bot, $self, $user, $msg, $choice) = @_;<br /><br /> if ($msg eq '')<br /> {<br /> $user_settings->{callback} = "snails";<br /> $self->sendmsg("(sn) Hello and welcome to the Snail Race Stadium (sn) \nPlease place your bets now by typing bet <snail number>\n(sn) 1, (sn) 2, (sn) 3,(sn) 4,(sn) 5.\nType 'start'");<br /> } <br /> elsif ($msg eq 'bet')<br /> { <br /> $self->sendmsg("$user bets on snail No. $msg! Any other bets?"); <br /> }<br /> elsif ($msg eq 'start')<br /> {<br /> $user_settings->{callback} = "";<br /> my $snails = [0,0,0,0,0];<br /> $self->sendmsg("Starting The Race....\n");<br /> my $winner = undef;<br /> <br /> while (not $winner) { #while there is no winner<br /> my $snail = int rand 5; #pick a snail<br /> $snails->[$snail]++; # move it<br /> $winner = $snail + 1 if ($snails->[$snail] ge 5); # did it win?<br /> $bot->do_one_loop(); #give other stuff a chance<br /> $self->sendmsg("going ....\n" . showsnails($snails)); #show them<br /> return "(sn) GONE!. Race over. Snail $winner won the race! (sn)"; <br /> }<br /> elsif ($msg eq 'exit')<br /> { <br /> $user_settings->{callback} = "";<br /> $self->sendmsg("The snail race had to be called off, the snail starting eating a lettuce leaf :P"); <br /> }<br /> <br /> else<br /> {<br /> return "Thats not a snail race option, type 'exit' to quit";<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 (5 - $snail) . "\n";<br /> }<br /> return $reply;<br />}