Extending Construct 2 with Javascript

Discussion and feedback on Construct 2

Post » Wed Feb 16, 2011 5:04 pm

That's what I started with. I'll wait a bit before I continue!
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Feb 20, 2011 11:30 pm

hi
I've been using construct for a couple of years now and have been wanting to write plugins
i know Java so learning JavaScript was quite easy for me
however i have never wrote a plugin before and have questions
first i am trying to replicate construct1's date plugin as practice

what i want to know is, where in the code do i place the object's variables/objects
like
var now = new Date();

i need to be able to store this and be able to call it back in the methods(functions but I'm too used to calling them methods(Java))
does anyone know how to do this?
am i too unclear?
B
2
G
2
Posts: 11
Reputation: 672

Post » Mon Feb 21, 2011 12:25 am

In all the object methods, 'this' refers to the current instance, so just do this.now = new Date() etc.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Mon Feb 21, 2011 1:05 am

thanks, that works(I'm still used to Java which you cant do that)

the way i figure it, the more plugins that i "translate" the less you have to do :D
i seem to be having another problem though

i tried replacing the pieExp expression but i am getting an error
Assertion failure: Cannot find object expression: Date.getmonth

my code is
[edit time]

AddExpression(0, ef_return_string, "getmonth", "Tutorial", "getmonth", "returns the month it is now. jan = 1 feb = 2 ...ect"); //same as the pieExp eccept i replaced it with getmonth

[runtime]

cr.plugins.DATE.prototype.exps = {};

(function()
{
// Get prototype for the expressions object that stores expression methods for an instance
exps["getmonth"] = function(ret) // all expressions take a 'ret' parameter
{
// Call set_string, set_int or set_float on the ret object to return a value
// The value returned from this function is ignored!
// If your expression has parameters, they follow on after 'ret', e.g.:
// function(ret, x, y)


ret.set_string( this.month);
};

oh i called the expression with the set text thing like this:
"month is: " & Date.getmonth
this worked with the tutorial stuff and have already edited actions with this with major success
can anyone tell me where the problem is?

EDIT: after i replaced the modified code with the original tutorial code
the problem still exists, im thinking that the problem might be in construct or the file is corrupted somehow
i guess somehow construct2 is not reading the info from that part of the runtime file
can some one confirm this
oh other than the expressions not working...... the rest of the plugin is coming along swimmingly
also, would it help if i uploaded the whole files?
B
2
G
2
Posts: 11
Reputation: 672

Post » Mon Feb 21, 2011 2:43 pm

The 'cannot find object expression' appears when the expression name in the AddExpression at edittime does not match the expression name at runtime. For example if your AddExpression adds "GetFoo", then you say exps["GetBar"] = function..., then it looks for "GetFoo" but can't find it.

In your example it looks like you've deleted a crucial line for some reason. You should have something like this:

[code:2myipk7s](function()
{
// This is the line you were missing, it creates a local 'exps' as a reference to the object expressions (this is taken from the Mouse object)
var exps = cr.plugins.Mouse.prototype.exps;

exps["X"] = function (ret) ...[/code:2myipk7s]

Without that line, you're writing the expression functions to a new global variable called 'exps', so C2 will never find the expression routine.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Mon Feb 21, 2011 10:56 pm

thanks Ashley! that helped
now that the expressions are working, I'm almost done.
i just need to add the conditions and then it will be ready for upload
construct2 is great! i have been running it off a flash drive at school! the portability function is awesome! (i wrote the plugin using like 4 computers)

quick question though.
how and where can i upload these things???
also, would it be possible to submit plugins to be distributed with future releases of construct2? or would you like to rewrite and distribute them yourself? i ask because i love construct and would like to help out in any way possible
B
2
G
2
Posts: 11
Reputation: 672

Post » Tue Feb 22, 2011 12:56 am

It's too early for us to have plugin distribution - try uploading them to dropbox or similar for now.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Tue Feb 22, 2011 9:36 am

As you say "SDK is subject to change at any time" and there is the talk of closed-source now is there much point in making plugins still?

Would a re-write make the current SDK not usable? or would we still be able to code a plugin now and it would work fine in later versions?
B
2
S
2
G
1
Posts: 121
Reputation: 1,092

Post » Tue Feb 22, 2011 5:08 pm

Do you write plugins only because it's open source? I don't get why that means "there's not much point" now.

We're not going to re-write Construct! Not again :S It's very much in our interests not to make any breaking changes, because it means we have to change all the official plugins too. To be honest, it's likely any changes will be minor, and if there aren't too many plugins, I can just go through and make the changes myself so nobody needs to worry about it. The 'change at any time' bit is just a disclaimer on the off-chance we do need to really give things a make-over, which I can't see any reason for in the near future.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Tue Feb 22, 2011 6:02 pm

All sorts of third-party folks have made plugins for MMF, and it's not open source.

Hell, the guy who posted above me used to do that very thing.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: Aphrodite, artbava, blackant, Bleenx, heliogame and 10 guests