Havin a little issue with my voting script. Every time I start this it just spams that the vote was tied meaning that it believes a vote was in session . It all looks perfectly fine to me but I bet the issue is a very silly one or perhaps a very large one. Who knows. In any case please have a look at it someone and set me straight
http://pastebin.com/zHhysvsv
The script is supposed to
*Tracks game time with gameTimeCurr
*When voting starts with the /vote command it sets gameTimeVoteEnd to higher value
*When the gameTimeCurr reaches it the vote session will end and compare the arrays of /yes and /no votes.
*/yes and /no have their own command array things and you cannot vote twice.
Just putting all this so you don't have to decipher all my nubbish looking code
PHP Voting Script
Re: PHP Voting Script
On line 37 you have an unintended semicolon:
Most languages that use C-style syntax will actually warn you about that empty statement for your if block. It's almost always unintended, and it will cause issues. Here's a short example for you:
Easy to misread, right?
There may be more issues, but that's the first thing I saw when reading your code.
Code: Select all
if ($gameTimeVoteEnd == $gameTimeCurr && $voteInSession == true);
Code: Select all
<?php
if (false);
{
echo "this block is always executed\n";
}
?>
There may be more issues, but that's the first thing I saw when reading your code.
Re: PHP Voting Script
The spamming is indeed caused by the line 37 semicolon, just remove it and it'll work.
Other optional stuff (it's not necessary to make it work but maybe fixes unintended behaviour):
You're currently using game_time which gives you the time from the start of the round in seconds which hangs up the vote when it's cast on the end of a very long round. You might want to use php's time() there:
also to not accidentally miss the end of the vote you can use
so you maybe also can increase your LADDERLOG_GAME_TIME_INTERVAL then for less ladderlog spammage
Oh, and also you might want to addright after you get $input=rtrim(...); so you can always kill the script via KILL_SCRIPT (as dlh states here). Not much of an issue but when the script gets larger it may be a good idea.
Other optional stuff (it's not necessary to make it work but maybe fixes unintended behaviour):
You're currently using game_time which gives you the time from the start of the round in seconds which hangs up the vote when it's cast on the end of a very long round. You might want to use php's time() there:
Code: Select all
$gameTimeCurr = time();
instead of
$gameTimeCurr = $param[1];
Code: Select all
if ($gameTimeVoteEnd >= $gameTimeCurr && $voteInSession == true)
instead of
if ($gameTimeVoteEnd == $gameTimeCurr && $voteInSession == true)
Oh, and also you might want to add
Code: Select all
if (feof(STDIN))
break;
Re: PHP Voting Script
Thank you all for the help!
I KNEW it was something very simple and silly like that. And thank you for the suggestions also.
I KNEW it was something very simple and silly like that. And thank you for the suggestions also.