Format Array JSON file?

0 favourites
  • 5 posts
From the Asset Store
Convert multiple Excel files into JSON files and import them into construct3.
  • Hey guys,

    I have created a simple Capx file that will let the user choose between a windowed or fullscreen node.webkit and save it to a JSON text file

    It works great but i want to be able to format the outputted "config.ini" JSON text file

    The output is as below:

    {"c2array":true,"size":[2,1,1],"data":[[["fullscreen"]],[[1]]]}[/code:5d8pxfhs]
    Id like to be able to format it to look like this
    [code:5d8pxfhs]fullscreen = 1[/code:5d8pxfhs]
    and eventually once I add more configurations, something like
    [code:5d8pxfhs][VIDEO]
    fullscreen = 1
    resolutionx = 1600
    resolutiony = 900
    
    [AUDIO]
    music = 26
    sound = 45
    
    [INPUT]
    Forward = 36
    Backward = 43
    Left = 13
    Right = 35[/code:5d8pxfhs]
    
    I believe to do this i would need to convert it to a string with tokens etc before saving and loading, i just have no idea how
    
    Any help would be great
  • You could set a string variable to "" (for ease I ll call it Textvar), do a repeat loop (you repeat ConfigArray.height times), inside it you have :

    Set Textvar to : textvar & ConfigArray.At(0, loopindex) & " : " ConfigArray.At(1, loopindex) & newline

    Hope that helps, I don t have C2 rit now so I cannot test

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the reply Aphrodite,

    Had to add another "&" symbol after the :

    But for the most part when I put display the results of Textvar in a Text Object it does show Fullscreen = 1 or 0

    My array now looks like this, but only Fullscreen and its value showed using the Textvar loop

    (0, 0) = Fullscreen

    (1, 0) = 1

    (0, 1) = Volume

    (1, 1) = 67

    I also attempted to add your set textvar equation value to a For Each Element in ConfigArray event, but it spammed the textbox and wouldnt stop :/

  • Managed to get it to work by using the Repeat condition and setting the count to "ConfigArray.Height"

    now i just need to figure out how to keep the newline when exporting it to a text file, right now it exports it all single line.

    Also im not sure, is there a way to do a "tab whitespace" in a string from construct 2?

    By that i mean, if you open up notepad in windows and press tab, it creates a space equal to pressing space bar at least 8 times, but it registers as a single character

  • Ashley,

    Not sure if its a bug, notepad or the node-webkit write action,

    Every time I export my string that contains "newline", it all appears on a single line, yet I open the same file in word-pad and each part is on a new line it should be.

    Also does an expression exist to show a "whitespace tab"?

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