Adding javascript library -- modifying header

For developers using the Construct 2 Javascript SDK

Post » Tue Aug 12, 2014 4:52 am

Hello,

I'd like to try out TaffyDB javascript based DB. To use TaffyDB I need to add a link to the library in the header tag. Is there a standard way in C2 to add js library links in the header?

thanks,

Dan
B
9
S
4
G
1
Posts: 207
Reputation: 1,385

Post » Tue Aug 12, 2014 12:50 pm

If you're using SDK to develop a plugin for your needs, refer to the manual: https://www.scirra.com/manual/18/plugin-settings and look for "dependency". They will automatically be added to the html file.

Cheers,

Nikola
Be nice until it's time to not be nice
B
36
S
10
G
9
Posts: 293
Reputation: 6,712

Post » Tue Aug 12, 2014 2:03 pm

I was hoping there was a way to include a library from with C2, without need for plugin dev.
B
9
S
4
G
1
Posts: 207
Reputation: 1,385

Post » Tue Aug 12, 2014 2:12 pm

You could try to use browser's "execute javascript" action and try to append script to head; something along the lines:

$('head').append( ... );

or

document.getElementsByTagName('head')[0].appendChild( ... );

but i'm not sure how it will work, and you'll probably have hard time debbuging it.

You can look on this thread here, seems like a lot of good info:

http://stackoverflow.com/questions/1900 ... javascript
Be nice until it's time to not be nice
B
36
S
10
G
9
Posts: 293
Reputation: 6,712

Post » Tue Aug 12, 2014 2:31 pm

By far the best way is to write a plugin using the Javascript SDK: https://www.scirra.com/manual/15/sdk

The Browser object’s ability to execute JavaScript should be regarded as a hack and not to be used if possible – prefer the SDK – but for very short bits of code can work OK.

From r175+ you can also use c2_callFunction(“name”, [param1, param2…]) to invoke a function in the Function object.
Refer to Function object manual entry (note: it won’t be written until the next stable update though, still noting it here for future references)
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
295
S
118
G
96
Posts: 7,327
Reputation: 71,246

Post » Tue Aug 12, 2014 3:32 pm

Probably off topic but is there a way to add a folder with the dependency key in edittime.js? I've tried and can't get it to work. To be fair unless your integrating a lib that's only a file or two then chances of porting to construct are slim, I've hit snags on plugins over this and gave up on them
B
11
S
2
G
1
Posts: 202
Reputation: 1,580


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests