How do I create array to root level JSON?

0 favourites
  • 6 posts
From the Asset Store
Awardkit
$5 USD
Create custom awards and achievement or use the many templates and create your own.
  • Hello,

    I want to create empty array to root level JSON like this:

    []

    so then i will add new objects with it later.

    for example:

    [ { "name": "outfit1", "image": "top1.png" }, { "name": "outfit29", "image": "top29.png" } ]

    I'm using this:

    JSON: Set "" to array size 4

    but it didn't work

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Example cdn.discordapp.com/attachments/225550155531812865/1209210754952335370/PushJSON_Into_RootArray.c3p

    {"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"on-start-of-layout","objectClass":"System"}],"actions":[{"id":"parse","objectClass":"JSON","parameters":{"data":"\"[]\""}}],"children":[{"eventType":"block","conditions":[{"id":"repeat","objectClass":"System","parameters":{"count":"4"}}],"actions":[{"id":"set-path","objectClass":"JSON","parameters":{"path":"\"\""}},{"id":"push-value","objectClass":"JSON","parameters":{"where":"back","path":"\".\"","value":"loopindex"}},{"id":"set-object","objectClass":"JSON","parameters":{"path":"\".\" & loopindex"}},{"id":"set-path","objectClass":"JSON","parameters":{"path":"\".\" & loopindex"}},{"type":"comment","text":"add data"},{"id":"set-value","objectClass":"JSON","parameters":{"path":"\".id\"","value":"loopindex"}},{"id":"set-value","objectClass":"JSON","parameters":{"path":"\".name\"","value":"\"user\" & loopindex"}},{"id":"set-value","objectClass":"JSON","parameters":{"path":"\".image\"","value":"replace(\"actor{0}.png\", \"{0}\", str(loopindex))"}}]},{"eventType":"block","conditions":[],"actions":[{"id":"set-text","objectClass":"TextInput","parameters":{"text":"JSON.ToBeautifiedString"}}]}]}]}
  • Wow,, you're amazing bro!

    the last one is:

    How to stop the JSON foreach

    I'm using

    System: Stop Loop

    But it's not working

    Therefore, I use boolean variable to indicate the 'found' state:

    I wonder if there is another efficient method to accomplish this situation.

  • The Stop Loop just work in System object. but you can use For

    + System: For "" from 0 to JSON.ArraySize("") -1
    
    {"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"for","objectClass":"System","parameters":{"name":"\"\"","start-index":"0","end-index":"JSON.ArraySize(\"\")-1"}},{"id":"compare-two-values","objectClass":"System","parameters":{"first-value":"loopindex","comparison":0,"second-value":"2"}}],"actions":[{"id":"set-path","objectClass":"JSON","parameters":{"path":"\".\" & loopindex"}},{"id":"set-text","objectClass":"TextInput","parameters":{"text":"JSON.GetAsBeautifiedString(\".\")"}},{"id":"set-text","objectClass":"TextInput","parameters":{"text":"JSON.Get(\".name\")"}},{"id":"stop-loop","objectClass":"System"}]}]}
    

    ---

    BTW: I submitted a suggestion to add more ACEs to JSON. If you are interested, you can add a ๐Ÿ‘ emoticon to the OP.

    github.com/Scirra/Construct-feature-requests/issues/8

  • Whoaa.. I didn't expect you to have explored this plugin so far...

    I really agree,

    Construct should add more attention to this plugin, because this plugin is very important in game development

  • I submitted a suggestion to add more ACEs to JSON. If you are interested, you can add a ๐Ÿ‘ emoticon to the OP.

    https://github.com/Scirra/Construct-feature-requests/issues/8

    BTW, how to add ๐Ÿ‘

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