QuincyDK's Recent Forum Activity

  • QuincyDK

    Hey, sorry I wasn't of more help either to your problem in the other post. What you just said made me ask myself : are those static data ? If so, the problem isn't the same. Executing code through execJS won't be a problem as it will only be for development. Once you've got the static data loaded in you array(s), you can use the "download" action to get there content as a C2 formated JSON file, that you will then be able to use in replacement of the execJS, for the real game.

    Hey there! It isn't static data, as we grab the data from one of our servers. This data differs per "file". Hence the function we've written to convert to a C2 JSON string.

  • I'm sorry I couldnt help you. Please inform me about your progress!

    It's no problem! Now things do get interesting, as we probably are going to run each input file through the converter manually

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There's one problem with construct about this: You can't create associative arrays. Maybe you'll have a look at ReyRainbows HashPlugin. It's awesome to store JSON data. Maybe you could extend this plugin to fit your needs.

    The data-structure is already working, and the converter we currently use is also working, we just want to merge them

    But, thanks anyways. It's nice to see that noobs like me have no reason to be afraid to ask something

  • The SDK documentation is not really helping me in this one. Could you perhaps share this plugin you're talking about, maybe I could implement my own function in there

    To be a little bit more percise: Here is what I want to do.

    I have a JSON file, I want to select this from my hard-disk during runtime (file-dialogue). The function sees this, and reads the file > Converts it into C2JSON > Pastes this in an array called "PicProperties"

    Seeing that I am pretty new to C2, I have absolutely no idea how to do this plugin-wise. This function should ONLY be called during runtime (Thus eliminating the need for edit-time stuff.) Does this mean that I could comment out the whole edit-time part except the plugin details and such?

    EDIT (again): I am figuring that this is an ACT. How would I go and add an "File select" dialogue in C2?

    And: How could I return values to an already existing C2 array?

  • var content="";
    var input="";
    var output="";
    var outputJson="";
    function readBlob(opt_startByte, opt_stopByte) {
    
        var files = document.getElementById('files').files;
        if (!files.length) {
          alert('Please select a file!');
          return;
        }
    
        var file = files[0];
        var start = parseInt(opt_startByte) || 0;
        var stop = parseInt(opt_stopByte) || file.size - 1;
    
        var reader = new FileReader();
    
        // If we use onloadend, we need to check the readyState.
        reader.onloadend = function(evt) {
          if (evt.target.readyState == FileReader.DONE) { // DONE == 2
            document.getElementById('byte_content').textContent = evt.target.result;
            document.getElementById('byte_range').textContent = 
                ['Read bytes: ', start + 1, ' - ', stop + 1,
                 ' of ', file.size, ' byte file'].join('');
                 content = evt.target.result;
    			 input = JSON.parse(content);
    			 output = {
        "c2array": true,
        "size": [input.frames.length, 4, 1],
        "data": input.frames.map(function(frame){
            return [
                [frame.image || ""],
                [frame.title],
                [frame.mediatype || ""],
                [frame.thumb || ""]
            ];
        })
    };
    
                    
    // the "null, 4" part is just to pretty-format the json (indent 4 spaces)
    var outputJson = JSON.stringify(output, null, 4);
          }
        };
    
        var blob = file.slice(start, stop + 1);
        reader.readAsBinaryString(blob);
      }
      
      document.querySelector('.readBytesButtons').addEventListener('click', function(evt) {
        if (evt.target.tagName.toLowerCase() == 'button') {
          var startByte = evt.target.getAttribute('data-startbyte');
          var endByte = evt.target.getAttribute('data-endbyte');
          readBlob(startByte, endByte);
        }
      }, false);
    
    /*
    {
      "name": "werwer",
      "frames": [
        {
          "title": "[Nieuwe Dia]",
          "image": "\\files\\cacc0075a0c044cbc9ec.jpg",  //without the filepath
          "thumb": "\\files\\cacc0075a0c044cbc9ec.jpg",  //thumb could be neglected
          "mediatype": null, //same as thumb
          "media": [] //same as thumb
        },
        {
          "title": "[Nieuwe Dia]",
          "image": null,
          "thumb": null,
          "mediatype": null,
          "media": []
        },
        {
          "title": "[Nieuwe Dia]",
          "image": null,
          "thumb": null,
          "mediatype": null,
          "media": []
        },
        {
          "title": "[Nieuwe Dia]",
          "image": null,
          "thumb": null,
          "mediatype": null,
          "media": []
        }
      ]
    };
    */
    
    var output = {
        "c2array": true,
        "size": [input.frames.length, 4, 1],
        "data": input.frames.map(function(frame){
            return [
                [frame.image || ""],
                [frame.title],
                [frame.mediatype || ""],
                [frame.thumb || ""]
            ];
        })
    };
    
                    
    // the "null, 4" part is just to pretty-format the json (indent 4 spaces)
    var outputJson = JSON.stringify(output, null, 4);
    console.log("test");
    console.log(output);
    document.getElementById("out").innerHTML = outputJson;[/code:11qmusfh]
    
    This following code, it is by the way.
  • I really recommend you to write a plugin and forget about the Browser object.

    For only one function, isn't that a bit of a lot of work?

  • Hey all,

    I'm looking for a way to insert my own function (array converter, perferably with file select dialogue but that could be scrapped). This function is already written and working. I came across some ways using a browser object, but I could not for the life of .. figure out how I could get this to work. Could anyone shed some light on this case for me?

  • I got a function, I want to import this into C2 and parse a file into this, saving it into an array.

    Is there a way to:

    1. Import a whole javascript function

    2. Have an file select dialogue

    I already have an HTML file select page with a converter function that converts a JSON file with our datastructure into a file that C2 understands. This is running on qdekoster.nl/testing.html (can't post complete urls yet) In the source code of this page, the function is also visible.

  • I do, however, have another question: Does C2 cary a function to convert JSON to a supported format?

  • Sorry for the day silence, I've been absent (dentist and birthday and stuff xD) Indeed Guizmus , patience is something you certainly have

    And I have to ask for a little bit more patience...

    {"c2array":true,"size":[2,1,1],"data":[[["test1"],["test2"]]]}[/code:3azz1ccf]
    
    This is my JSON as I am still figuring out the ins and outs before I push this to our development cycle. The array is named List, and List.At(1) returns 0 instead of the expected "test2" and I can't for the life of it seem to figure out what is going wrong 
    
    EDIT: Scrap that out, I figured it out (seems that Construct refuses to load the array if I use one bracket instead of two)
  • To be more percise: I call the AJAX command to pull in the JSON. However, when I set "Text to AJAX.LastData" , I get an empty text container. This makes me think that there is something in the data retrieval that doesn't work.

  • Arrays in C2 are all 3-dimensional. No more, no less. So it should be ok.

    I'm terribly sorry to bother you again..

    Now I have this JSON

    {"c2array":true,"size":[10,1,1],"data":[[["Test1"]],[["Test2"]],[["3"]],[[40]],[[5.0]],[[60000]],[[7,0]],[[8.000.000]],[[9*10]],[[10]]]}[/code:usizcc2k]
    
    I load this into my project with AJAX and (try to ) parse this into my array. When I call Array.At(0) I get an 0 back. What would be the correct way to call from the array say the 2nd position? (Array.At(1) I guess right?)
    
    Error is fixed. Anyhow, how can I populate instance variables with JSON data at index 0, 1 etc etc? That's more or less the question.
    
    This is all run from preview btw.
    
    Edit: Also from my own server (using an export) I get nothing.
QuincyDK's avatar

QuincyDK

Member since 17 Feb, 2014

None one is following QuincyDK yet!

Trophy Case

  • 10-Year Club
  • Email Verified

Progress

11/44
How to earn trophies