Picking objects with scripts.

  • Messing around with the scripting feature a bit, and one thing that I can't figure out is how to pick objects by for example a variable, or by position, or is within a certain radius of another object or anything else.

    Does anyone have a hands on example on how to do that, that i can study further?

    Preferably with some comments so i can understand what's going on, as I'm pretty new to javascript.


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's not currently supported. It might be difficult to add a feature for it, too. There are several critical performance optimisations for picking through sub-events that impose strict rules on which objects can be picked. So in general script could not simply go ahead and pick instances in some arbitrary object - unless we de-optimised the entire event engine to allow it.

    Maybe the best solution would be to come up with some way of combining picking with JS callbacks, e.g. using "Pick by evaluate" calling a JS function.

  • Okay. That sounds reasonable.

    It just seemed a bit odd that actions could be scripts but not conditions at this point.

    I was mostly thinking in cases like the Ghost Shooter example in JS, that had some utility scripts. If you somehow could have a set of JS functions that you use regularly, it would be great addition if they could also be used for picking. Since it would be quite easy to share and reuse in other project since the function it self doesn't contain any references to any specific objects, and you pass your parameters through when calling the JS Function.

    // Test if a given instance is outside the bounds of the layout.
    function IsOutsideLayout(inst)
    	const layout = inst.layout;
    	return inst.x < 0 || inst.y < 0 ||
    			inst.x > layout.width || inst.y > layout.height;

    Pick Sprite by Evalute - JSfunction("isOutsideLayout")param0,param1,param2,param3)

    I'm imagining it would return the UID's that were outside of layout.

    :) Just an idea... not sure how useful it would be, but it might come handy in some cases.

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