Communication between two Plugins

0 favourites
  • 8 posts
From the Asset Store
Footsteps SFX Two contains 450 sounds of steps and jumps on different surfaces.
  • Hi, I am new to the SDK.

    I am making two plugins, and I want them to communicate with each other.

    How should I proceed in this case?

    Thankyou.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In general, plugins should not communicate with each other. It tends to be a brittle and inflexible design. What are you trying to do exactly? Normally there's a better way to do it.

  • In general, plugins should not communicate with each other. It tends to be a brittle and inflexible design. What are you trying to do exactly? Normally there's a better way to do it.

    Hi, Ashley.

    I was wondering if declaring a global object would be a good idea. Like var amalkantiIP={} outside all blocks.

    I am using some Payment APIs.

    There will be several plugins and I want not to load everything. So I am dividing them into parts by making several plugins.

  • I'm afraid it's still not clear to me what you're trying to do, why there needs to be communication, and why it can't be solved just by exposing triggers and actions in your plugins so there doesn't need to be any cross-plugin communication (which is the preferred design).

  • Actually I am using one plugin for loading API SDKs. This will be a Central Plugin. This plugin will contain all the property value like API-Keys and such to be entered by the user. Then the other plugins are named according to the Payment API I am using (for e.g.- Stripe).

    The First Plugin will also allow the data to be saved on a database easily and manage users.

    So instead of using the same code for the database again and again in each of the plugins I want to make this Central Plugin, that will have function and properties that any of the other plugins can call or use.

  • Hi Amalkanti, refer to this Note:

    GetSavedDataMap()

    GetUnsavedDataMap()

    Return a Map to store additional data to associate with this instance. Use string keys only, and ensure keys are unique. The saved data map is written to savegame files so should be used for persistent state. The unsaved data map is not written to savegame files so should be used for transient storage or caching.

    Do not simply add new JavaScript object properties to Construct's runtime classes. This will cause the JavaScript engine to deoptimise performance for all code using the class. These data maps are provided as a convenient alternative. You can also use a WeakMap with Instance keys to associate data with instances without leaking memory or modifying the instance class at all.

    Link- https://www.construct.net/en/make-games/manuals/addon-sdk/runtime-reference/object-classes/instance

    In the "Central" plugin as you said, include this code in the Instance.js (runtime)-

    	//Central Plugin - Instance.js (runtime)
    
    	//Set data with WeakMap in your Central Plugin Object Class
    	this._objectClass.GetUnsavedDataMap().set("myData", "1");
    

    Then in your second plugin include these codes-

    	//Second Plugin - Plugin.js (edittime)
    
    	//Create an object Selector Property
    	this._info.SetProperties([
     new SDK.PluginProperty("object", "name")
     ]);
    
    	//Second Plugin - Instance.js (runtime)
    
    	//Get the Selected Object from the Properties
    	var CentralPlug_Obj = this._runtime.GetObjectClassBySID(properties[indexNo]);
    	//Get Data from WeakMap of your Central Plugin Object Class
    	var yourData = CentralPlug_Obj.GetUnsavedDataMap().get("myData")
    
  • In general, plugins should not communicate with each other. It tends to be a brittle and inflexible design. What are you trying to do exactly? Normally there's a better way to do it.

    Hi Ashley, can you please review the above solution. (I am not much experienced) What consequences can it lead to if we communicate in this way?

  • Hi, Thanks Sparsha. Maybe can I also use globalThis.Variable for making the variables global?

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