common.js?

Get help using Construct 2

Post » Thu Nov 10, 2011 10:49 am

Hey, now that I've encountered duplicate functions in both edittime and runtime, I've been wondering about common.js, where common functions are meant to be.

But there is no information on how should I declare those plugins. How would I refer to functions in common.js? Is there a certain naming convention?
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Nov 10, 2011 2:22 pm

I was also wondering about how to use common.js.
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Thu Nov 10, 2011 2:57 pm

There's nothing special about common.js, it's just copy-pasted to the top of both the edittime and runtime script files. So if you have function FooBar() { ... } in both edittime and runtime, cut and paste it to the common file and it should be available in both.

Edit: oh, but those functions end up in the global namespace. It would be best to create your own namespace in common.js, so it doesn't conflict with any other plugins, e.g. in common.js:

[code]var MyObjectCommon = {};

MyObjectCommon.FooBar = function () { ... }; // etc[/code]

then in both edittime and runtime you call MyObjectCommon.FooBar(), and it should avoid any name collisions.Ashley2011-11-10 15:00:34
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Thu Nov 10, 2011 3:28 pm

That's what I wanted to know, thanks Ashley!
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Nov 10, 2011 9:52 pm

Thanks Ashley. And thanks Mipey for bringing it up. I forgot to ask.
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608


Return to How do I....?

Who is online

Users browsing this forum: gregorysforster, jeffige, Matthew de and 1 guest