QuincyDK's Forum Posts

  • 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)
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.
  • Well basically it's for an prototype of a media application. We store data (text, filename if relevant, filepath if relevant and info like that) into an json. That's the reason why we want to import json files into our project, to follow our data structure.

    However, are multidimensional arrays within the scope of C2 Json?

  • So basically I'm stuck with an 0-index-based aray? If so, could I just create variables and populate them by using the 0-based index of the aray?

  • Ah, okay * goes to work *

    Thank you

  • here is my text.capx file. The JSON has a data structure comparable (or actually directly ripped from) to our project.

  • And here is an example on how to download an array as a json file, and how to load an array from a json project file. (the project file is empty, it's only for the events)

    Thanks alot! I think the reading goes correctly now Problem number 2, parsing it.

    RIght now I have (built alongside your example:

    EVENT SHEET {

    1. SYSTEM | On start of layout [ AJAX | Request testing.json (tag JSON)]

    2. AJAX | On "JSON" completed [ Array | Load from JSON string AJAX.LastData ]

    3. MOUSE | On Left button Clicked on [T] Text [Text2 | Set test tp Array.At(0) ]

    I guess you can see what I try to do here. If user clicks on text2, I want the text to change to the first key in the array. Ofcourse, since I'm such a noob at C2, this doesn't work :') *ashamed*

  • QuincyDK

    i'm not sure I follow entirely what you want but here is my take on it.

    If you need to populate an array based on a JSON you build outside of C2, there are 2 ways :

    - if you want to load the JSON during runtime, you could have the JSON file in the project files, and just replace it on your server. Use an event "On start of layout : AJAX load project file myJSON.json" and another "AJAX on finished loaded : Array.loadFromJSON(AJAX.LastData)"

    - if you want to populate the array before the runtime (so inside the C2 editor), just add an event "on start of layout : Array.loadFromJSON(X)", where X is the string representing the JSON content (in one line of course).

    If you need to have the format of an Array JSON representation in C2, just do some Alert or console.log of a populated array during any runtime, and copy paste its "asJson" expression.

    I hope this was what you were looking for, I'm not sure at all x)

    I'm terribly sorry to keep on asking, but I'm new to C2. Where would I find this AJAX object? Is AJAX a plugin or..? Also: Where could I insert raw JS (Alert(); and console.log();

  • For runtime, using the array will be easier.

    For saving/restoring purposes you can get the datas of an array object as JSON quite simply, using the expression "Array.AsJSON". Then, you have to use this JSON. As it's for a back-end dev, I would suggest sending it via AJAX.

    Something like this.

    I can't deny that this is very interesting and a good tip, the reading from json is more important right now as the json will be created backend. However, this is merely for a prototype thus everything will be "static". For this purpose, we'd like to read from a json file (multidimensional would be prefered) and use this in our CS2 prototype.

  • yep it can be done.

    Using either layer scale or scaling the image.

    for moving across the image you could just use system scrollto and if youd like to make it very easy on yourself there is the litetween plugin.

    Thank you! The Litetween plugin was exactly what I was looking for

  • Hi there,

    We currently use an array for datastorage, but to follow our back-end development we'd like to use JSON files instead.

    The documentation of CS2 isn't getting me anywhere, so could anyone explain me how this all works? *is new to CS2*