PHP Voting Script

Everything todo with programming goes HERE.
Post Reply
SoulOfSet
On Lightcycle Grid
Posts: 30
Joined: Tue Feb 22, 2011 3:54 am
Contact:

PHP Voting Script

Post by SoulOfSet »

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 :)
User avatar
dlh
Formerly That OS X Guy
Posts: 2035
Joined: Fri Jan 02, 2004 12:05 am
Contact:

Re: PHP Voting Script

Post by dlh »

On line 37 you have an unintended semicolon:

Code: Select all

if ($gameTimeVoteEnd == $gameTimeCurr && $voteInSession == true);
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:

Code: Select all

<?php
if (false);
{
	echo "this block is always executed\n";
}
?>
Easy to misread, right?

There may be more issues, but that's the first thing I saw when reading your code.
User avatar
vov
Match Winner
Posts: 568
Joined: Thu Feb 17, 2011 8:40 pm

Re: PHP Voting Script

Post by vov »

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:

Code: Select all

$gameTimeCurr = time();
instead of
$gameTimeCurr = $param[1];
also to not accidentally miss the end of the vote you can use

Code: Select all

if ($gameTimeVoteEnd >= $gameTimeCurr && $voteInSession == true)
instead of
if ($gameTimeVoteEnd == $gameTimeCurr && $voteInSession == true)
so you maybe also can increase your LADDERLOG_GAME_TIME_INTERVAL then for less ladderlog spammage ;)

Oh, and also you might want to add

Code: Select all

if (feof(STDIN))
        break;
right 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.
SoulOfSet
On Lightcycle Grid
Posts: 30
Joined: Tue Feb 22, 2011 3:54 am
Contact:

Re: PHP Voting Script

Post by SoulOfSet »

Thank you all for the help! :D

I KNEW it was something very simple and silly like that. And thank you for the suggestions also. :D
Post Reply