509Dave16's Forum Posts

  • My last post wasn't very helpful. However I think I found what you need. So here's some more code:

    var objectTypesArray = this.runtime.types_by_index;
    var NameTypePairs = {};
    var TypeInstNameIndexPairs = {};
    for(var araIndex in objectTypesArray)
    {
        var objTypeID = objectTypesArray[araIndex];
        var objInst = this.runtime.createInstance(objTypeID, this.layer);
        var instVarNames = objInst.instance_var_names;
        var instVars = inst.instance_vars;
        var InstNameIndexPairs = {};
        for(var instVarIndex in instVarNames)
        {
    		var name = instVarNames[instVarIndex];
    		var index = instVarIndex;
    		InstNameIndexPairs[name] = index;
        }
        var objType = objInst.type;
        this.runtime.DestroyInstance(objInst);
        var objName = objType.name;
        NameTypePairs[objName] = objType;
        TypeInstNameIndexPairs[objName] = InstNameIndexPairs;
    }
    var dialogboxType = NameTypePairs["dialogbox"];
    var dialogboxTypeInstVars = TypeInstNameIndexPairs["dialogbox"];
    var nameVarIndex = dialogboxTypeInstVars["name"];
    var dialogboxInst = dialogboxType.instances;
    
    for(var instIndex in dialogboxInst)
    {
       var inst = dialogboxInst[instIndex];
       if(inst.instance_vars[nameVarIndex] = "Joe")
       {
           var instJoe = inst;
       }
       if(inst.instance_vars[nameVarIndex] = "Jasper")
       {
           var instJasper = inst;
       }
    }
    
    instJasper.visible = false;
    instJoe.text = ".........";
    instJoe.visible = true;
    [/code:3goj65s5]
    This is assuming that the 'name' Instance Variable of the dialogbox Object Type.
  • As an example say we wanted to check the Text value of each Text Plugin Object Type Instance. You could use this statement to access the value:

    this.type.instances[index].text;[/code:2uk93qx3]If you look at the implementation of the Text Plugin, you'll find in the runtime.js that the Instance.onCreate has a 'text' member variable. If you wanted to look at the "Instance Variables" that you added at Edit Time you could use these statements:
    [code:2uk93qx3]
    var instIndex = 0;
    var varStr = 'text2';//made up instance variable added in the editor
    var varIndex = -1;
    var inst = this.type.instances[instIndex];
    var instVarNames = inst.instance_var_names;
    for(var instVarNameIndex in instVarNames)
    {
       if(instVarNames[instVarNameIndex] = varStr)
       {
           varIndex = instVarNameIndex;
       }
    }
    var instVarValue = inst.instance_vars[varIndex];
    [/code:2uk93qx3]
  • [/code:2wuzpy2g]I understand what you are talking about now. I've been attempting to look into how to access the Plugin Object Type Instances(basically just instances of objects). If you look at the 'Object type' and 'Instances' manual entries under the 'SDK Reference', you'll find useful information regarding the attainment of instances of an Object Type. I'm still researching on how to do this, because I've seen a few other requests like yours. Through Javascript you need to try obtaining the text contents of the Prototypes\Functions\Objects that are assigned to an Instance. Here are a few lines of code that you can put in a Plugin Action that should get you started:
     [code:2wuzpy2g]
    		var objectTypesArray = this.runtime.types_by_index;
    		var araLength = objectTypesArray.length;
    		var instValuesArray = [];
    		for (var araIndex = 0; araIndex < araLength;  araIndex++)
    		{
    				var instObj = this.runtime.createInstance(objectTypesArray[araIndex],this.layer);
    				var valueStr = "";
    				for(var item in instObj)
    				{
    					valueStr += item + " : " + instObj[item] + "\n";
    				}
    				valueStr+= "\n\n\n\n\n";
    				instValuesArray[araIndex] = valueStr;
    		}
    [/code:2wuzpy2g]
    You want to most likely set an entire String representation of the instValuesArray to a property of the Plugin you  built(or a test Plugin). Then access that property through an expression at runtime in the Event Sheet, setting an Array Plugin Instances first dimension first element to that property's string. Then use the Array's Download Action to save the Array in a file as JSON. You'll have to use a text editor and what not format the element's text in the JSON file. Basically you have to inspect this String to find out where the Names of the Object Type and the Instance Properties\Variables are in the chain. Then from there figure out how to access them so that you can set for example your SpriteFont's text. I hope this helps somehow.
  • You do not have permission to view this post

  • Hey, shukshuk! Could you by chance further clarify your question about binding a function to a Sprite Font Element? Are you wanting to update the Sprite Font element with a value returned from your getNextDialogLine(actor_a,actor_b,state) Plugin Action?

  • When I get home from work, I could send you my Skype ID and we could see if there's anything I can do to help. I haven't been using Construct 2 for very long, but I might be able to help you.

  • To create a plugin you have to use the sdk template for a plugin or modify an already existing plugin which is risky. There are no other easier ways. I have the template zip file attached to my post.

  • Divinity: Original Sin and Wasteland 2.

  • , you are welcome. The way I did the Saving and Loading of the JSON files was an attempt to strictly use Construct 2 Actions, which isn't the best because of some limitations. If there was a way to have a file imported into the Construct 2 project at Runtime using some kind of a System Action, then you wouldn't have to manually import JSON files into the project.

  • Hey, ! I'm kind of a noob when it comes to Construct 2, though I've been trying to discover some form of a "save" functionality that you just described for saving JSON. As it stands there is this tutorial(manual entry) called 'Using project files in Construct 2' on scirra.com. If you search for the 'Making level editors' section in the manual entry, it will describe some plugins you could use to save data, which are the Array and Dictionary Plugins. Both the Array and Dictionary Plugins have DownloadJson and LoadJson Actions which can be used to store the data in a file and load the data from a JSON string. You'll also need the AJAX plugin to request the JSON file. Below I'm providing an attached .capx demo project of saving/loading the JSON. I'm using Project files though so I had to import the test_json.json file that contains the saved JSON format of the Array Plugin Object that I used in the demo project to store a JSON string of the example_json.json file. It automatically asks you to save a file test_json.json upon running the project. And you can click the 'LOAD JSON' button to load the JSON format of the Array Plugin which was orginally saved and then imported into the project unfortunately. If you used the Request GET or Request POST Actions to call scripts to return/save the JSON instead of the RequestFile Action on the Ajax Plugin, you could bypass the need to import files and use the Array Plugin. And if you're interested search for this work in progress Plugin for parsing/forming JSON strings: '[plugin] JSON (import/export/generate/edit/inspect/...)' .

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well for example you could have un-movable Sprite or Text Plugin Objects that you've placed to act as the GUI elements like buttons, tab panes, right click menus, and the like . The trick is how do you populate the menu screens with dynamic elements like Inventory Items or Stats. Thus for example you'd probably have a json/xml file where Inventory Items or Stats are defined having a name, value, image name, etc.. . Then you'd use the System Condition OnLayoutStart I believe to trigger the loading Event logic you would create to load in those said Inventory Items or Stats. That logic would probably involve the Ajax Plugin to load the file and either the XML or JSON Plugin to parse the file. Then once you have all the data loaded into say Array or Dictionary Plugin Objects then you'd have to have additional Event logic to create instances of Sprite or Text Plugin Object Types. You'd also have to include logic that could determine where these objects need to be placed on screen and on what layer. Then for actual GUI control actions, you'd have to define say the Event logic that would display the information of an item in a pane upon clicking a Sprite Item Object in the Inventory screen. These are just some quick thoughts. I haven't created a menu myself. But I've been thinking it over and have had these ideas regarding how it could be done. You might want to search the forum for 'C2 Plugins and Behaviors List' to see if there are any Plugins/Behaviors that could help you with building a menu. There are many steps to developing a good flexible menu. You could probably start with a simple Main Menu of the game that would be seen on launching the game. In fact there's probably a tutorial that contains instructions/demo project that has a Main Menu defined. Best of luck to you in your Menu Making endeavors.