Thread: Voting Npc
View Single Post
  #2  
Old 07-30-2011, 07:00 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Here's some problems with your script:
  • It's not styled properly.
  • You're using an assignment instead of a comparison in your if statements.
  • You're using chat to store the votes.
  • Your script can break easily, and votes will reset if the NPC goes to sleep and onCreated gets called, and anyone who voted will have to unvote which will cause your survey values to go into the negatives.
  • It's not documented at all.

Solutions
  • Indent your code. See Code Gallery example. If you aren't sure you're styling it right use http://jsbeautifier.org
  • if (variable == value) not if (variable = value).
  • Use a server or a DB variable to store the votes, and update your NPC to display it in chat. I.e: server.survey_votes
  • Track a Survey ID, and only allow them to vote it their clientr.voted isn't the current Survey's ID. I.e: server.survey_id
  • Document and place comments in your code. See Code Gallery example.

Quote:
Originally Posted by fowlplay4
How to style your script properly with jsbeautifer.org

Copy-paste your code into the code text area.

Settings:
- Indent with 2 spaces
- Braces with control statement
- Un-check all Checkboxes

Click 'Beautify'
Here's an example of basic Code Gallery post: http://forums.graalonline.com/forums....php?p=1660882
__________________
Quote:
Reply With Quote