[Plugin] Function-like Namespaces

  • Namespaces

    Namespaces are virtually identical to the core Function plugin. The only difference is that you can create more than one Namespace object. If you're using a lot of functions, you can break them up into multiple Namespace objects, helping organize your code and prevent name collisions.

    You add, call, and inspect Namespace objects exactly like you would the vanilla Function object.

    Namespaces are independent from one another ? calling a function from namespace A should never trigger a function in namespace B.

    A Very Simple Demo

    Downloads

    namespace.c2addon

    namespace_demo.capx

    Some notes:

    • This plugin is literally the core Function plugin with the singleton tag taken out and the some strings judiciously edited. All credit goes to the fine folk who developed the function plugin for creating such a robust piece of code.
    • Unlike the Function plugin, namespaces aren't singletons. That means that it's technically possible to create and destroy namespace objects, among other things. I wouldn't particularly advise using those features, but, hey, I'm not your boss. The practical upshot is that the Namespace event windows are a bit more cluttered than the vanilla Function object.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • <font color=red><font size="4">IMPORTANT UPDATE (Edit: Problem resolved! See below)</font></font>

    After more testing, it appears that my plugin breaks when used with nested function calls. I'll update the original post accordingly.

    I guess I now know why there was such a song and dance with the func stack.

    Edit: Well, apparently I can't edit the OP because I don't have enough rep to post the hyperlinks that are already there?

  • <font color=red><font size="5">UPDATE 2 - Problem resolved!</font></font>

    Well, it turns out that the bug I thought I had was nothing but a red herring. I'm a bit embarrassed to say that I missed converting a function call to a namespace call in some code I was converting, and erroneously assumed that the plugin was at fault.

    I now am quite sure that the plugin is working as intended!

    I've nonetheless updated the plugin download link to an new version of the plugin. The major change of note is that individual namespace objects now maintain their own function stacks. This will probably prevent weird collisions with nested namespace calls.

    I've also updated the demo to be much more extensive and easier to read. Be sure to clear your browser cache if you've looked at it before.

  • Made a minor update to this plugin

    Changes in version 1.0.5

    • Error messages now include the name of the namespace.
    • Return value error messages include the value the action was trying to return

    The demo has been updated to demonstrate the new error messages (in preview mode, of course)

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