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