15 Replies Latest reply on Nov 16, 2012 12:17 PM by try67

    SyntaxError in JavaScript

    GameHermit Level 1

      Hi Everyone,

       

      I have a javascript that passes values to other fields based on a dropdown list selection. All is working well but now when I try to add a line of code to the script I get one of two different errors.

       

      First...here's the javascript that is working properly:

       

       

      var WeaponChoice = {
       ' ':{ meleeyn: "-1", minstrength: "0", range: "", weapondamage: "0", diceadd: "2", poordamage: "", weaponnotes: ""},
      Battleaxe:{ meleeyn: "1", minstrength: "50", range: "--", weapondamage: "2D+", diceadd: "2", poordamage: "1D+2", weaponnotes: "Minimum STR 50"},
      Club:{ meleeyn: "1", minstrength: "0", range: "--", weapondamage: "1D+", diceadd: "1", poordamage: "", weaponnotes: "Cost 1GP"}, 
      Crossbow:{ meleeyn: "0", minstrength: "50", range: "80", weapondamage: "2D+", diceadd: "2", poordamage: "1D+2", weaponnotes: "Minimum STR 50"},
      Dagger:{ meleeyn: "1", minstrength: "", range: "--", weapondamage: "1D+", diceadd: "0", poordamage: "", weaponnotes: ""},
      'Dagger (thrown)':{ meleeyn: "0", minstrength: "", range: "10", weapondamage: "1D+", diceadd: "0", poordamage: "", weaponnotes: ""},
      Flail:{ meleeyn: "1", minstrength: "50", range: "--", weapondamage: "2D+", diceadd: "1", poordamage: "1D+1", weaponnotes: "Minimum STR 50"},
      Glaive:{ meleeyn: "1", minstrength: "55", range: "--", weapondamage: "2D+", diceadd: "3", poordamage: "1D+3", weaponnotes: "Minimum STR 55"},
      Greataxee:{ meleeyn: "1", minstrength: "70", range: "--", weapondamage: "3D+", diceadd: "0", poordamage: "2D", weaponnotes: "Minimum STR 70"},
      Halberd:{ meleeyn: "1", minstrength: "60", range: "--", weapondamage: "2D+", diceadd: "3", poordamage: "1D+3", weaponnotes: "Minimum STR 60"}}; 
      
      function WeaponScripta(WeaponInfo) { 
          // Weapon 1 Information  
          this.getField("M1").value = WeaponChoice[WeaponInfo].meleeyn; 
          this.getField("MinSTR1").value = WeaponChoice[WeaponInfo].minstrength;
          this.getField("WR1").value = WeaponChoice[WeaponInfo].range;
          this.getField("WD1").value = WeaponChoice[WeaponInfo].weapondamage; 
          this.getField("PoorDMG1").value = WeaponChoice[WeaponInfo].poordamage;
          this.getField("DADD1").value = WeaponChoice[WeaponInfo].diceadd;
          this.getField("WN1").value = WeaponChoice[WeaponInfo].weaponnotes;
      }
      
      

       

      If I try to add the following line I get a "SyntaxError: missing ] in index expression 22: at line 23":

       

      Handaxe:{ meleeyn: "1", minstrength: "0", range: "--", weapondamage: "1D+", diceadd: "2", poordamage: "", weaponnotes: ""}
      
      

       

      If I try to add the following line I get a "SyntaxError: missing } after function body 22: at line 23":

       

      'Hand crossbow':{ meleeyn: "0", minstrength: "0", range: "30", weapondamage: "1D+", diceadd: "1", poordamage: "", weaponnotes: ""}
      
      

      I'm kind of at a loss as to why I can't add more lines.

       

      Thanks for looking at this with me

       

      Jack

        • 1. Re: SyntaxError in JavaScript
          Test Screen Name Most Valuable Participant

          Where exactly are you trying to add these lines? From the line numbers it looks as if you may be just sticking them at the end, rather than inside the definition of WeaponChoice.

          • 2. Re: SyntaxError in JavaScript
            GameHermit Level 1

            Thanks for the reply

             

            I'm trying to add the lines between the last set of close curly brackets. So the last line:

             

            Halberd:{ meleeyn: "1", minstrength: "60", range: "--", weapondamage: "2D+", diceadd: "3", poordamage: "1D+3", weaponnotes: "Minimum STR 60"}}

             

            I'm trying to add a line between the closing curly brackets like this:

             

            Halberd:{ meleeyn: "1", minstrength: "60", range: "--", weapondamage: "2D+", diceadd: "3", poordamage: "1D+3", weaponnotes: "Minimum STR 60"},

            Handaxe:{ meleeyn: "1", minstrength: "0", range: "--", weapondamage: "1D+", diceadd: "2", poordamage: "", weaponnotes: ""}

            }


            I hope this helps

            • 3. Re: SyntaxError in JavaScript
              GameHermit Level 1

              Are there limitations on the number of lines a variable can have?

              • 4. Re: SyntaxError in JavaScript
                try67 MVP & Adobe Community Professional

                Did you add a comma at the end of this new line?

                • 5. Re: SyntaxError in JavaScript
                  GameHermit Level 1

                  No...didn't add a comma. does it need one?

                   

                  LOL...sory..I'm teachiing myself all of this so I don't have a lot of experience.

                  • 6. Re: SyntaxError in JavaScript
                    try67 MVP & Adobe Community Professional

                    Yes, unless it's the last element in the list it must have a comma at the

                    end of it (after the closing curly brackets).

                    • 7. Re: SyntaxError in JavaScript
                      GameHermit Level 1

                      Actually it was the last item so I didn't add the comma. Is there a limit or something that is restricting the number of items that can be in the variable? I tried replacing one of the existing (working) lines with one of the items I mentioned in the first post and they worked. But as soon as I go beyond the number of items I currently have listed I get the error.

                      • 8. Re: SyntaxError in JavaScript
                        try67 MVP & Adobe Community Professional

                        No, it's not an issue with a limit to the number of items. Could you post

                        the complete code you're using?

                        • 9. Re: SyntaxError in JavaScript
                          GameHermit Level 1

                          Sure thing...and thank you so much for the help. I've added the last two items ('Hand crossbow' and Handaxe)...if you remove these items it works. But even if you add just one of these items the script doesn't work. Here's the code:

                           

                          var WeaponChoice = { ' ':{ meleeyn: "-1", minstrength: "0", range: "", weapondamage: "0", diceadd: "2", poordamage: "", weaponnotes: ""}, Battleaxe:{ meleeyn: "1", minstrength: "50", range: "--", weapondamage: "2D+", diceadd: "2", poordamage: "1D+2", weaponnotes: "Minimum STR 50"}, Club:{ meleeyn: "1", minstrength: "0", range: "--", weapondamage: "1D+", diceadd: "1", poordamage: "", weaponnotes: ""}, Crossbow:{ meleeyn: "0", minstrength: "50", range: "80", weapondamage: "2D+", diceadd: "2", poordamage: "1D+2", weaponnotes: "Minimum STR 50"}, Dagger:{ meleeyn: "1", minstrength: "", range: "--", weapondamage: "1D+", diceadd: "0", poordamage: "", weaponnotes: ""}, 'Dagger (thrown)':{ meleeyn: "0", minstrength: "", range: "10", weapondamage: "1D+", diceadd: "0", poordamage: "", weaponnotes: ""}, Flail:{ meleeyn: "1", minstrength: "50", range: "--", weapondamage: "2D+", diceadd: "1", poordamage: "1D+1", weaponnotes: "Minimum STR 50"}, Glaive:{ meleeyn: "1", minstrength: "55", range: "--", weapondamage: "2D+", diceadd: "3", poordamage: "1D+3", weaponnotes: "Minimum STR 55"}, Greataxe:{ meleeyn: "1", minstrength: "70", range: "--", weapondamage: "3D+", diceadd: "0", poordamage: "2D", weaponnotes: "Minimum STR 70"}, Halberd:{ meleeyn: "1", minstrength: "60", range: "--", weapondamage: "2D+", diceadd: "3", poordamage: "1D+3", weaponnotes: "Minimum STR 60"}, 'Hand crossbow':{ meleeyn: "0", minstrength: "0", range: "30", weapondamage: "1D+", diceadd: "1", poordamage: "", weaponnotes: ""}, Handaxe:{ meleeyn: "1", minstrength: "0", range: "--", weapondamage: "1D+", diceadd: "2", poordamage: "", weaponnotes: ""}};

                          function WeaponScripta(WeaponInfo) {

                              // Weapon 1 Information 

                              this.getField("M1").value = WeaponChoice[WeaponInfo].meleeyn;

                              this.getField("MinSTR1").value = WeaponChoice[WeaponInfo].minstrength;

                              this.getField("WR1").value = WeaponChoice[WeaponInfo].range;

                              this.getField("WD1").value = WeaponChoice[WeaponInfo].weapondamage;

                              this.getField("PoorDMG1").value = WeaponChoice[WeaponInfo].poordamage;

                              this.getField("DADD1").value = WeaponChoice[WeaponInfo].diceadd;

                              this.getField("WN1").value = WeaponChoice[WeaponInfo].weaponnotes;

                          }

                          • 10. Re: SyntaxError in JavaScript
                            try67 MVP & Adobe Community Professional

                            I don't have the file, but the code itself compiles just fine (ie, there

                            are no syntax errors).

                            • 11. Re: SyntaxError in JavaScript
                              GameHermit Level 1

                              I don't know if this helps but here's a screenshot of the editor when it kicks out the error...it highlights the next tho the last line for some reason:

                               

                              SyntaxError.png

                              • 12. Re: SyntaxError in JavaScript
                                GameHermit Level 1

                                weird...maybe I should just copy out the code then recreate a new script?

                                • 13. Re: SyntaxError in JavaScript
                                  try67 MVP & Adobe Community Professional

                                  Very odd... Actually, I was trying to help someone else today with a similar strange error... Could be a bug in Acrobat.

                                  I would try removing the code completely, saving the file, closing Acrobat, then opening the file and re-applying the code.

                                  If you still get this error message, report it to Adobe as a bug.

                                  • 14. Re: SyntaxError in JavaScript
                                    GameHermit Level 1

                                    This is strange...instead of opening the script individually, I used "edit all javascripts" and it worked fine.

                                     

                                    Crazy!

                                     

                                    Thank you for your help

                                    • 15. Re: SyntaxError in JavaScript
                                      try67 MVP & Adobe Community Professional

                                      Using Edit All JavaScripts is not recommended, as you can very easily

                                      remove one of the built-in tags and totally mess up your file.