Format Array JSON file?

Get help using Construct 2

Post » Mon Jun 23, 2014 10:28 am

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
Image
The output is as below:
Code: Select all
{"c2array":true,"size":[2,1,1],"data":[[["fullscreen"]],[[1]]]}

Id like to be able to format it to look like this
Code: Select all
fullscreen = 1

and eventually once I add more configurations, something like
Code: Select all
[VIDEO]
fullscreen = 1
resolutionx = 1600
resolutiony = 900

[AUDIO]
music = 26
sound = 45

[INPUT]
Forward = 36
Backward = 43
Left = 13
Right = 35


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
B
6
S
3
Posts: 39
Reputation: 632

Post » Mon Jun 23, 2014 10:44 am

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
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Mon Jun 23, 2014 11:36 am

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 :/
B
6
S
3
Posts: 39
Reputation: 632

Post » Thu Jun 26, 2014 12:40 pm

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
B
6
S
3
Posts: 39
Reputation: 632

Post » Fri Jun 27, 2014 6:37 am

@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"?
B
6
S
3
Posts: 39
Reputation: 632


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 27 guests