- Home /
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>';
}
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 = "\"";
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?
There's nothing wrong with UnityScript @Baste , it's not a "bad" or 'bad' language.
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.
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.
Your answer
Follow this Question
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