Is it possible to reference things outside of your plugin?

0 favourites
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • These might be painfully obvious and I'm not just seeing them. I might also be trying to make the plugin system do what it isn't intended to do.

    Is there a way, for example, to access a list/object/array/whatever of all of the sprite instances on a layout and act on them?

    Can I reference a behavior from my custom behavior? For example, could I set path targets and initiate movement programmatically?

    Thirdly, is there a way to access a "global" variable that is persistent? Does runtime.extra function that way?

    Thanks for any/all help! Actually, is there a more "informal" api reference? I feel like there's a lot more available than what is in the SDK reference? Am I wrong?

  • Yes , it is possible to reference other plugin or behavior. For example, reuse ACE in your plugin or behavior-

    http://c2plugins.blogspot.tw/2014/02/reuse-ace.html

  • I want to say thank you for that. Those examples taught me a lot about how to go about writing a C2 plugin. In the example of calling an action, is there an easier way of finding the parent instance instead of traversing the plugins array? In this example, a behavior that on create sets the width of the sprite it's attached to.

  • The owner of one behavior could be got by "this.inst" directly, "this" is the behavior.

  • Thank you so much. I am much more comfortable with how to navigate the different parts of c2 now.

    What is the preferred method of having a global data structure? In HTML5 I'd use window as the global namespace, but am I allowed to be sure the window object will be the root when exporting?

  • I am not sure, it depends on your plan.

  • I just want a big sloppy object floating around in the global namespace for me to store all of my game specific variables. I'm unfamiliar with a lot of what construct does on the backend to export things and don't want to shoot myself in the foot by referencing window if there is a preferred solution. It should be noted I'm not intending on releasing what I write.

  • I would strongly recommend you do not design plugins that operate on any part of the game that the user does not explicitly tell it. For example don't automatically find objects and work with them - require the user to add the object via an object parameter before your object works on it. This avoids surprising "magical" behavior that can't be turned off, conflicts with other plugins that take the same unwise approach, and allows the user to exercise control over precisely what your plugin does. I would give more specific advice if you had mentioned exactly what you're trying to achieve.

    For private global data, just put some variables in the file-level closure that wraps everything. It will be global to all instances and types, and it does not pollute the global namespace or attach any junk to "window".

  • Ashley

    The dependence to other plugin could reuse current plugin/behavior , or just add some decorator to these objects. Yes, I agree the dependence will let user confuse, but it could be solved by clear document.

  • but it could be solved by clear document.

    Assuming users read documentation

    In the past we've even had messageboxes pop up with very clear instructions on what to do, and users still come to the forum asking why it doesn't work.

  • Don't worry I have NO intention of releasing any sort of plugin unless it conformed with whatever coding standards.

    I really really love construct2 for how abstracted the code is, all of the features built in, and the top notch layout/map editor. I very rarely finish games so much as work on concepts, and feel much more comfortable slogging through code than a UI.

    My current theory is that custom plugins/behaviors make it very easy to write the bulk of my game's code as custom plugins/behaviors but still retain all of the sweet features of the engine like exporting to different platforms.

    I toyed with impactjs for years but it seems he only makes occassional bug fixes, so the community dev environment never hammered out good ways to export or extend. C2 has more features and actually gets updated. C2 is top notch. I wish I was a creative type to take better advantage.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not sure if I still have anyone's attention, but related question:

    please excuse the psuedo code but I want to accomplish something like

    When this.runtime.trigger(someplugin.onCondition) , but I need to somehow daisy chain it to an action, so that when onCondition gets flagged my code knows to implement the Action

    In other words I want to fully use ACE via javascript

    "on condition" -> trigger(action).

    I see the runtime object has an event queue but don't seem to find a way to add a condition check to it.

    (I was able to figure out how to use the CR object to invoke actions on other instances/behaviors/plugins, but not how to connect an action to a condition).

    "OnTrigger"s only fire once and I have no way to capture them.

  • It sounds like you want to hijack a condition on the event sheet to execute your plugin code as well as the action that was specified in the event sheet? If that's the case then the easiest solution is to just create an ACE action item for your plugin and then in the event sheet add it to the actions you call when a condition is triggered.

    Your only other option is to override the ACE condition its self so when the condition is triggered its your code that executes. I have done this myself with regard to the Multiplayer plugin but it was much easier because the plugin used internal functions that triggered its own conditions so instead of overriding the ACE condition i just had to override the internal function and decide to either trigger my condition or the default one.

    In your case you might try something like this to override the original.

    cr.plugins_.SOMEPLUGIN.prototype.cnds.CONDITIONAME = function(){
           //Copy all original code that is suppose to execute and then add you own
    }
    [/code:ujtxo7g3]
    
    You will how ever need to override it during the instantiation of your plugin and not add it as a direct function because the this needs to be overridden after the original plugin has been interpreted.
  • I guess sometimes the simplest solution is the best. It really is the easiest method to just expose an action that can be called from the event sheet. Over riding is a pretty easy solution too depending on which thing you're over riding.

    Thanks!

    If there is something similar to an "add this condition to watch for then execute this action" function that anyone knows of please let me know!

  • skelooth

    Most of case, I am using an action to trigger a condition, like official function plugin, or ajax does. You could reference ajax plugin first, or see this.

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