Theres my MSN objects....Everything else seems fine...
But when the code below is used, it is multigames in which it has to deliever messages to a room periodically to tell them that time is running out ect... But on some messages it sends the twice! I've searched long and hard for an explanation.. But havent got a clue....
Notice i only have 2 mirrors, is this a link? should i try with 3 to see if it sends it 3 times...
From what i can see it seems the gameover messages and new round messages are sent once but ones that describe time is running down appear twice...
Here is my WHOLE timeres sub....thank you for any help
Code:
<br />sub addTimers{<br /> my $self = shift;<br /> <br /> #Too keep convo's open.<br /> $timer->addforever(code => sub {<br /> my($timer,$msn) = @_;<br /> foreach my $handle (keys %{$bot->{msn}}) { <br /> foreach my $convo (values %{$bot->{msn}->{$handle}->getConvoList()}){<br /> $convo->sendtyping();<br /> }<br /> }<br /> }, data => $bot->{msn}, interval => 120);<br /> #Snap timer <br /> $timer->addforever(code => sub {<br /> my($timer,$msn) = @_;<br /> my $snapon;<br /> foreach my $handle (keys %{$bot->{msn}}) { <br /> foreach my $convo (values %{$bot->{msn}->{$handle}->getConvoList()}){<br /> if(defined $convo->{in} && $convo->{in} eq "snap"){<br /> $snapon = "on";<br /> }<br /> }<br /> }<br /> if(!defined $snapon){<br /> $snapon = "off";<br /> }<br /> if($snapon eq "on"){<br /> &snap($self);<br /> } <br /> else{<br /> return;<br /> }<br /> }, data => $bot->{msn}, interval => 1);<br /> <br /> #The scramble's Timer<br /> $timer->addforever(code => sub {<br /> my($timer,$msn) = @_;<br /> <br /> my $time = time;<br /> $bot->{store}->{general}->{chatrooms}->{scramble}->{time} = time - 38 if(!defined $bot->{store}->{general}->{chatrooms}->{scramble}->{time});<br /> my $gone = $time - $bot->{store}->{general}->{chatrooms}->{scramble}->{time};<br /> my $chatroom = "scramble";<br /><br /> if($gone == 20){<br /> my $message = "20 Seconds left! - Unscramble $bot->{store}->{general}->{chatrooms}->{scramble}->{scrambled} to win 5 points!!"; <br /> my $color = "009900";<br /> &chatAnnounce($message,$chatroom,$color);<br /> $bot->{store}->{general}->{chatrooms}->{scramble}->{worth} = 5;<br /> }<br /> elsif($gone == 30){<br /> my $word = $bot->{store}->{general}->{chatrooms}->{scramble}->{word};<br /> my @blanks;<br /> my @chars = split(//, $word);<br /> my $first = shift (@chars);<br /> my $last = pop (@chars);<br /> foreach my $item (@chars) {<br /> push (@blanks, "_");<br /> }<br /> unshift (@blanks, $first);<br /> push (@blanks, $last);<br /><br /> my $hint = join (" ", @blanks);<br /> my $message = "10 Seconds Left! - Unscramble : $bot->{store}->{general}->{chatrooms}->{scramble}->{scrambled} to win 2 points!\nHint : $hint";<br /> my $color = "0099ff";<br /> &chatAnnounce($message,$chatroom,$color);<br /> $bot->{store}->{general}->{chatrooms}->{scramble}->{worth} = 2;<br /> }<br /> elsif($gone >= 40){<br /> my $message = "Gameover - Starting a new round.";<br /> &chatAnnounce($message,$chatroom);<br /> my ($unscram,$scram) = &get_random_word;<br /> $bot->{store}->{general}->{chatrooms}->{scramble}->{word} = $unscram;<br /> $bot->{store}->{general}->{chatrooms}->{scramble}->{scrambled} = $scram;<br /> $bot->{store}->{general}->{chatrooms}->{scramble}->{time} = time; <br /> $bot->{store}->{general}->{chatrooms}->{scramble}->{worth} = 10;<br /> $message = "New round : The scrambled word is : $scram - Unscramble it for 10 points!";<br /> &chatAnnounce($message,$chatroom);<br /> } <br /> }, data => $bot->{store}, interval => 1);<br /><br /> #Trivia <br /> $timer->addforever(code => sub {<br /> my($timer,$msn) = @_;<br /> if(!defined $bot->{store}->{general}->{chatrooms}->{trivia}->{answer}){ &startTrivia;}<br /> my $time = time;<br /> $bot->{store}->{general}->{chatrooms}->{trivia}->{time} = time - 38 if(!defined $bot->{store}->{general}->{chatrooms}->{trivia}->{time});<br /> my $gone = $time - $bot->{store}->{general}->{chatrooms}->{trivia}->{time};<br /> my $chatroom = "trivia";<br /><br /> if($gone == 20){<br /> my $message = "40 Seconds left! - Question : $bot->{store}->{general}->{chatrooms}->{trivia}->{question} to win 10 points!!" if(defined $bot->{store}->{general}->{chatrooms}->{trivia}->{question}); <br /> my $color = "009900";<br /> &chatAnnounce($message,$chatroom);<br /> $bot->{store}->{general}->{chatrooms}->{trivia}->{worth} = 10;<br /> }<br /> elsif($gone == 40){<br /> my $word = $bot->{store}->{general}->{chatrooms}->{trivia}->{answer};<br /> my @blanks;<br /> my @chars = split(//, $word);<br /> my $first = shift (@chars);<br /> my $last = pop (@chars);<br /> foreach my $item (@chars) {<br /> push (@blanks, "_") unless ($item eq " ");<br /> push (@blanks, " ") if($item eq " ");<br /> }<br /> unshift (@blanks, $first);<br /> push (@blanks, $last);<br /><br /> my $hint = join (" ", @blanks);<br /> my $messager = "20 Seconds Left! - Question : $bot->{store}->{general}->{chatrooms}->{trivia}->{question} to win 5 points!\nHint : $hint";<br /> <br /> &chatAnnounce($messager,$chatroom);<br /> $bot->{store}->{general}->{chatrooms}->{trivia}->{worth} = 5;<br /> }<br /> elsif($gone >= 60){<br /> my $message = "Gameover - Starting a new round.";<br /> &chatAnnounce($message,$chatroom);<br /> &startTrivia;<br /> }<br /> }, data => $bot->{store}, interval => 1);<br /><br /> #Timed blocks <br /> $timer->addforever(code => sub {<br /> my($timer,$msn) = @_;<br /> foreach my $blocked (keys %{$bot->{store}->{blocks}}){<br /> if(defined $bot->{store}->{blocks}->{$blocked} && $bot->{store}->{blocks}->{$blocked} < time){<br /> delete $bot->{store}->{blocks}->{$blocked};<br /> $msn->call($blocked,"[!] OK, Youre block has expired.\nBut remember you will be blocked again if caught flooding!");<br /> }<br /> } <br /> }, data => $bot->{msn}, interval => 5);<br />}
This problem occures in snapz, trivia, scramble, So if you can notice one im sure it is reflected in the others...
Anyway, i had the sub being called in sub connected, and i then relised this wasnt being called just the once! Therefore the timers were being added twice.....