Quote:
Originally Posted by Gunderak
Update.
Here is the latest new and improved version.
Thanks fowlplay for your help.
code...
|
You're still using an assignment instead of a comparison in your if statements. I.e:
if (clientr.voted = 0) {
should be
if (clientr.voted == 0) {
You also don't need to use a timeout at all. You only need to update the chat when the npc is created, and when a player votes. You can write a function called updateChat() to take care of that for you.
PHP Code:
function updateChat() {
this.chat = "Votes: " @ server.votes;
}
You should also avoid using returns to stop the script from executing further, it can sometimes make your script difficult to follow.
Re-factored:
PHP Code:
function onCreated() {
updateChat();
}
function onPlayerchats() {
if (player.chat == "/vote") {
if (clientr.voted == 0) {
player.chat = "Voted!";
server.votes += 1;
clientr.voted = 1;
updateChat();
} else {
player.chat = "You've already voted!";
}
}
else if (player.chat == "/unvote") {
if (clientr.voted == 1) {
clientr.voted = 0;
player.chat = "Unvoted!";
server.votes -= 1;
updateChat();
} else {
player.chat = "You haven't voted yet!";
}
}
}
function updateChat() {
this.chat = "Votes: " @ server.votes;
}
I still don't think this 'voting' npc is all that helpful since you can only agree with it, and you don't get any kind of statistic from those who disagree. I.e: Voting Yes or No.
Your code still needs to be updated to support multiple/changing the survey, and to be documented.