Extending Construct 2 with Javascript

0 favourites
From the Asset Store
Casino? money? who knows? but the target is the same!
  • {#} is zero indexed.

    It is showing {1} in the event editor because there isn't a 2nd parameter.

    Use {0} instead and it should work.

  • Thanks

  • Quick question. What do you use when none of flags apply? I am trying to make an array plugin; pf_singleglobal wouldn't apply to it, since it'd have to be multi-instanced. None of position/size ACE flags apply, either, since array is not a layout object.

    So I set "flags": null, however that appears to cause a glitch; even though it is a non-layout object, when you add the object, it goes into layout placement mode. Click and it throws error.

  • "flags": 0

    Zero means no flags!

  • Ah, thanks. Probably want to document that.

    Ninja edit: setting the "flags": 0 still causes that glitch, where non-layout object behaves as placeable world object (throwing the error as you place it)

  • I have just been wondering something....

    Since C2 uses library's like Jquery which i think has MIT License, when other objects are made possibly using other library's with other licenses how will this effect commercial use and would you have to credit all the library's in use etc?

    I am guessing there will be some sort of notice for the objects list when they have one and web content like Jquery they are generally very relaxed but i figured i should ask.

  • Both MIT and BSD licenses allow for commercial use, providing you leave in the license text.

  • Still grokking along with that array plugin. Seems that non-layout objects don't display properties. Moreover, that "flags" : 0 seems to regard the object as a layout object.

    Doesn't look like I'll get anything useful done at the moment.

  • Yeah, you want a non-layout non-single-global plugin type for Array, which unfortunately there isn't support for right now...

    Edit: did you also try setting "type": "object" in the plugin settings?

  • That's what I started with. I'll wait a bit before I continue!

  • 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?

  • In all the object methods, 'this' refers to the current instance, so just do this.now = new Date() etc.

  • 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

    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?

  • 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:

    (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.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)