GetPluginSettings -> Unexcepted token

Bugs will be moved here once resolved.

Post » Mon Aug 08, 2011 10:46 am

Although my JavaScript skills are rusty, but what's the difference?

[CODE]
function GetPluginSettings()
{
     return
          {
          "name":               "Demo",
          "id":               "Demo",
          "description":     "Demo description.",
          "author":          "Demo",
          "help url":          "http://demo.com",
          "category":          "Demo",
          "type":               "object", // not in layout
          "rotatable":     false,
          "flags":          pf_singleglobal
     };
};
[/CODE]

VS

[CODE]
function GetPluginSettings()
{
     return {
          "name":               "Demo",
          "id":               "Demo",
          "description":     "Demo description.",
          "author":          "Demo",
          "help url":          "http://demo.com",
          "category":          "Demo",
          "type":               "object", // not in layout
          "rotatable":     false,
          "flags":          pf_singleglobal
     };
};[/CODE]

For me, everything is valid but Construct interpreted it differently.

[Quote]
---------------------------
HTML5 exporter
---------------------------
Unable to load plugin in 'C:\Daten\Tools\Construct 2\exporters\html5\plugins\demo\': Javascript exception in file 'edittime.js' line 5: SyntaxError: Unexpected token :

Code line:
          "name":               "Demo",

Stack trace:
SyntaxError: Unexpected token :

This plugin will not be available in the editor.
---------------------------
OK   
---------------------------
[/Quote]
B
23
S
4
G
7
Posts: 98
Reputation: 5,220

Post » Mon Aug 08, 2011 11:20 am

Your 'id:' should be "demo" or your folder's name should be "Demo".
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Mon Aug 08, 2011 2:38 pm

Javascript automatic semicolon insertion

The code
[quote]return
{[/quote]

is parsed as
[quote]return;
{[/quote]

which means 'return undefined;' followed by a chunk of JSON which is then ignored. The solution is to use

[quote]return {[/quote]

all on one line, then it won't insert a semicolon for you.

Yep, Javascript is mad.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,508

Post » Mon Aug 08, 2011 10:52 pm

Thank you for the explanation. I already thought I'm stupid
B
23
S
4
G
7
Posts: 98
Reputation: 5,220

Post » Sat Aug 20, 2011 7:16 am

Indeed pure madness.
The style
if()
{
}
is incorrect in javascript, and must be written as
if(){
}Fimbul2011-08-20 07:16:27
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Sat Aug 20, 2011 2:05 pm

Is it? The entire javascript runtime is written in the style

if ()
{
}

It works just fine. I think the semicolon insertion rules don't break that.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,508

Post » Mon Aug 22, 2011 3:44 am

Actually I was wrong, it works for if() and functions, but breaks for returns:

Check @ 30:40 http://www.youtube.com/watch?v=hQVTIJBZook
Maybe ECMAScript 5 strict mode is fixing it, I don't know, but it certainly breaks things in conventional javascript in some occasions.


I prefer the curly braces below the statement too, but what can I do? :(Fimbul2011-08-22 03:45:52
B
35
S
8
G
8
Posts: 532
Reputation: 6,868


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest