[plugin] JSON (import/export/generate/edit/inspect/...)

0 favourites
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • not sure how i can add new entry's in a array object, from the inspection capx example, i guess the root object is an array, these contain 5 objects, and these objects has all the data and furter nested arrays

    found this nice online editor

    http://www.jsoneditoronline.org/

  • vtrix

    I'm at work now, but know that the root object can be whatever you want it to be: an object (a.k.a. dictionary), an array, a boolean, a number, a string or null.

    By default, root is undefined (or should be, I don't remember what I do )

    The brackets [] you see in the event sheet are just because I don't have a lot of options as far as formating the look of action/condition/expression. Those brackets should contain the path to a value. Nothing to do with type.

    In the example with the Wizard class,

    • root[] is the base (which in this case is an object)
    • root["Wizard"] is the value at the "wizard" key in the root object, and it is also an object
    • root["Wizard","hp"] is the value at the "hp" key contains in the object at the "Wizard" key of the root object.

    and so on and so forth.

    I'll keep calling this type "object", because that's what it is called in the official JSON documentation and in javascript, but do think of it as a dictionary (key value pair)

    As far as confusion with objects in construct...

    Well in construct you don't really have objects per se.

    You have plugins, object-types (created from plugins) and instances (created from object-types).

    You don't really have "objects" (well, the term is usually mis-used interchangeably as a shorthand for object-types or instances... talking about confusion ).

    And in any case, object-types or instances have nothing to do with a JSON object.

    I repeat again, an object in JSON is the same as a dictionary in construct2 (and in python it's also called a dictionary)

  • yes, i agree the object term is just whats used in json and should stay like this, im just going thru the plugin and actually the json structure and making sense of it, here are some reference i found usefull,

    http://www.w3resource.com/JSON/structures.php

    http://json.org/

  • Yann

    Been playing with with this last night, and all morning and looks great so far.

    [ ] brackets are a little misleading maybe instead use curly brackets { } like in "typical" json, and keep [ ] brackets for arrays to avoid confusion.

    set 2 at current{"dex"}

    think it looks a bit better then:

    set 2 at current["dex"]

    or maybe even none of them, just:

    set 2 at current "dex"

    just a thought

  • Found one issue, nothing fancy but still.

    Like on attached image.

    if your cursor is currently on "Value" and you press TAB couple of time it goes from "Value" to "Reference point" and then to "Add parameter".

    TAB'ing ignores added parameters, but Shift+TAB works fine - moves backwards from "Add parameter" through "Key 1", "Key 0".... to Value"

    Edit: Sorry for that huge image, it looks smaller while saving it

  • shinkan

    Yeah maybe square brackets are misleading:

    Here's a better representation of what we could get

    // square
    root[]
    root["Wizard"]
    root["Wizard","stats"]
    root["Wizard","stats","hp"]
    // curly
    root{}
    root{"Wizard"}
    root{"Wizard","stats"}
    root{"Wizard","stats","hp"}
    // normal
    root()
    root("Wizard")
    root("Wizard","stats")
    root("Wizard","stats","hp")
    // angle
    root<>
    root<"Wizard">
    root<"Wizard","stats">
    root<"Wizard","stats","hp">
    // nothing
    root 
    root "Wizard"
    root "Wizard","stats"
    root "Wizard","stats","hp"[/code:k20702zz]
    What do you prefer?
    note that's it's really only an esthetic/cosmetic consideration. It will change nothing in how it works =)
  • shinkan

    What you describe is actually a (minor) bug you also have in the function plugin =)

    Funny one, I never got around to report it.

    But it's something that should be solved by Ashley.

  • shinkan

    Yeah maybe square brackets are misleading:

    Here's a better representation of what we could get

    // square
    root[]
    root["Wizard"]
    root["Wizard","stats"]
    root["Wizard","stats","hp"]
    // curly
    root{}
    root{"Wizard"}
    root{"Wizard","stats"}
    root{"Wizard","stats","hp"}
    // normal
    root()
    root("Wizard")
    root("Wizard","stats")
    root("Wizard","stats","hp")
    // angle
    root<>
    root<"Wizard">
    root<"Wizard","stats">
    root<"Wizard","stats","hp">
    // nothing
    root 
    root "Wizard"
    root "Wizard","stats"
    root "Wizard","stats","hp"[/code:j6zuevqm]
    What do you prefer?
    note that's it's really only an esthetic/cosmetic consideration. It will change nothing in how it works =)
    

    Though choice

    For only one parameter "nothing" looks cleanest - root "Wizard"

    but for multiple parameters "normal" have more sense to it - root("Wizard","stats","hp")

    If I had to choose, I would go with "normal"

    shinkan

    What you describe is actually a (minor) bug you also have in the function plugin =)

    Funny one, I never got around to report it.

    But it's something that should be solved by Ashley.

    Oh. I don't recall that in function plugin... Just double checked that and no issue here. Can TAB back and forth with "name" and "parameters" (one or many) in function plugin while creating a new function, or editing existing one.

  • It should be root~"Wizard","stats","hp"~

    But just for Wizard

  • shinkan

    Ok my bad, I think I've seen it on the function plugin at some point but I might have dreamt that

    Anyway, I don't think I did something wrong setting up the UI, it might be some iffy secret stuff going on Ashley side I'm not aware of. (maybe having a comboParam before a variadicParams mess things up...)

    And unfortunately I don't have enough control to do "nothing if there's nothing and parenthesis if there's something"

    I can only put

    <i>[{...}]</i>[/code:14bpo4jg]as far as I know, to tell the plugin to display [parm0,param1,param2,...] in italic with and with 0 param it will leave the brackets the same way you still have the parenthesis even with no parameters in the function call action.
    
    @newt  nice one =)
  • vtrix

    An idea for you, going back to your post about weapons:

    You could put a JSON object in container with your weapon object type.

    This way you could have automatic picking, but also you weapon JSON could have a structure like this:

    {
      "name": "rifle",
      "surname": "MyLittleRifle",
      "fireRate": 0.5,
      "damage":5,
      "bullets":[
        {type:"superbadass",perforation:5,speed:500,"fx":"flash"},
        {type:"medium",perforation:1,speed:300,"fx":"flash"},
        {type:"fake",perforation:0,speed:0,"fx":"smoke"},
      ]
    }[/code:2vu1jnjt]
    
    This way you can imagine a game were weapons can be picked, dropped, with their amunitions, the amunitions can be removed, sorted, placed in other weapons, and each bullet have specific properties. The "bullets" property would be an array where the order is used to shot them sequencially.
    
    And since it's a container, each weapon you have in your layout could have very different or random properties. And to organize your project better you can even put information about animation or frames to play/display, this way you can leave all your weapon frames in the same sprite and same for bullets.
    Everything synched with just one object instead of a lot of array/dictionnary
    
    Maybe a few things would be redundant with instance variables... but meh
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yann , great idea's, but where i was pointing at with the weapons, was an inventory that would be divided by weapontype (shields,swords,etc..) but now i already know alot more on how i would put it together.

    i've made some progress with my first tests,

    https://dl.dropboxusercontent.com/u/616 ... index.html

    (you can click on the first icons)

    basicly 3 objects as "folders", in the folders you have arrays with again objects with the data, and ofcourse inside.. theres..another array, inception!

    now next will be the hard part, modifying data, connecting data, how to get a specific array entry, etc..

    im wondering if everything is supposed to happen in the json object or are there parts where i should generate a c2.array and work with that and then reimport to the json

  • vtrix

    Not really sure what I'm looking at, but it sure looks neat

    And it seems that you manage to get the hang of the plugin pretty well :]

  • at least it looks neat, yeah just displaying some data,

    going further, so if you want to do something with an array,

    lets say a drag and drop rearrange of items in the array

    would you suggest to make a temp array or somehow manipulate the json array itself

    well i guess the best way would be to duplicate the json array, then you can use the arrayfeatures

    but then how do you work with the object inside? any insights?

  • Well, depends on what you want to do but in general, the basic functions you want to have with arrays are access using index and as a by product of that, being able to loop through the entries.

    To loop, you just have to use the basic C2 repeat or for loop. The plugin has the JSON.Length(origin,p,a,t,h,...) expression that returns the length of the array at the given path. All you need to loop.

    If you start messing with array indices though (like creating holes in the indexing) you'd have to check for undefined durring your looping.

    Otherwise, other functions like push/pop/shift/unshift/insert/delete (what you would need for drag&drop and rearrange) are indeed not implemented. It's not too hard to implement via events using loop, but it would probably be better to have the javascript functions directly. Though you would only be able to push/unshift simple values (not object or array)) unless I do something like JSON.pushJSON(origin,p,a,t,h,...)... Not sure I would want to go that far.

    Otherwise, the foreach loop implemented in the plugin is for looping through object (but you can use it to loop through arrays as well, though I wouldn't trust the ordering on that one)

    So yeah in the end, the only feasible way to move objects arround is to so a insertJSON, pushJSON and unshiftJSON. Converting the branch of the object you want to move to JSON and that would be parsed and inserted as a new object.

    I might throw a new capx with some example of that tomorrow night. If I have time =)

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