Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by leahmeeee_ · Feb 09, 2015 at 04:30 PM · javascripterrorarrayquizsemicolon

expected. Insert a semicolon at the end. When the end that it says, is a } Could someone help us fix this?

We are working on putting arrays on our hardcoded android quiz game. We searched for example codes such as the code in this one : http://coursesweb.net/javascript/trivia-game-script_s2 (or in the attachment)

But when we tried to run it on Unity, errors will show. For example,

Assets/trivia/trivia.js(43,4): UCE0001: ';' expected. Insert a semicolon at the end.

When the end that it says, is a }

Could someone help us fix this?

(A PART OF THE CODE)

   var quizzes = [];
   // sets the <select> list with categories, that will be added in #tcateg
   // Receives an object with "category":"file_name" elements, and the type of the files ('xml', or 'json')
   this.setCateg = function(objf, type) 
   {
     objfiles = objf;
     var tcateg = '';  var propf = '';
     var i = 0; // to can call the method that sets the quizzes, with the first file_name
     for(var prop in objfiles) 
     {
       if(i === 0) propf = prop;
       i = 1;
       tcateg += '<option value='+ prop +'>'+ prop +'</option>';
     }
     // calls thee method to set the trivia quizzes of first category
     if(type == 'xml') obth.setQuizXML(propf);
     else obth.setQuizJSON(propf);
     // sets onchange event for <select> with method to call according to type, adds the select list
     var onchg = type == 'xml' ? 'onchange="obTrivia.setQuizXML(this.value)"' : 'onchange="obTrivia.setQuizJSON(this.value)"';
     if(document.getElementById('tcateg')) document.getElementById('tcateg').innerHTML = 'Trivia Category: <select '+ onchg +'>'+ tcateg +'</select>';
   }




Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlwaysSunny · Feb 09, 2015 at 03:02 PM 0
Share

What type are you expecting the tcateg and propf variables to be? You must use "double quotes" for strings and 'single quotes' for chars. I've never seen single quotes around more than a single char - is that a real thing? $$anonymous$$ight try changing those to doubles.

If you need quote characters within your string, you can use escape characters:

 // single quote character as string 
 string singleQuote = "\'";
 // double quote character as string
 string doubleQuote = "\"";
avatar image Baste · Feb 09, 2015 at 04:41 PM 0
Share

Because it's a bad language, you can use single quotes around strings in JavaScript. Because UnityScript is a bad language that emulates JavaScript, you can use single quotes around strings in UnityScript.

Doesn't mean that you should do it, though.

This question is about a JavaScript tutorial that seems to have nothing to do with Unity. It also uses a program$$anonymous$$g language that's not used in Unity. Why was it let through moderation?

avatar image Lo0NuhtiK · Feb 09, 2015 at 04:46 PM 0
Share

There's nothing wrong with UnityScript @Baste , it's not a "bad" or 'bad' language.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by steakpinball · Feb 09, 2015 at 07:05 PM

It looks like you are trying to use javascript from a web page inside Unity. Unfortunately that doesn't work. The 'javascript' which unity uses is actually UnityScript.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Seneral · Feb 09, 2015 at 07:39 PM

The problem lies in line 21, the {} begins in line 4 which defines a delegate. This means there has to be a semicolon, unlike regular if clauses for example.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Texture2d[]: Array index is out of rang (Javascript) 3 Answers

Making a pick up item that is timed, that moves,scales and rotates 1 Answer

IndexOutOfRangeExeption - Array index is out of range 2 Answers

Create array of children in Start function, use it in Update? 1 Answer

GetComponents array in C# error ? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges