Yann's Recent Forum Activity

  • Bl4ckSh33p

    I see no problem here

    make sure you load a proper JSON string.

    Good test is to copy paste the exact input you try to load in http://jsonlint.com and see if it's a valid string.

    for example

    {"realms": []}[/code:15yo6a9a] is a valid json string, but [code:15yo6a9a]test({"realms": []})[/code:15yo6a9a]is obviously not.
  • mfdeveloper

    I'm not using construct that much these days. But if I remember correctly the plugin has something like

    LoadJSON "{""name"": ""test"", ""age"",""xxx""}" at root@'some','kind','of','path'[/code:iu5f956j]
    which would exactly achieve what you described without having some nasty parsing. Something like[code:iu5f956j]Set Value "{o_o}" at root@ 'smilies','0'[/code:iu5f956j] should be expected to work
    
    has for sharing things on github, yeah, I should, three years ago I wasn't really using it that much so I didn't have this reflex.
  • keepee

    Yeah I'm still roaming around sometimes like an old ghost.

    Well... These days I'm not "constructing" that much, I'm more into unity, and I've became proficient enough to feel quite limited when I try something on construct :D...

    That being said, if I remember correctly and after having reread a bit of the plugin, I'm actually drawing the polygon in a 2D (non webgl) canvas and then using the resulting texture on a WebGL quad.

    And according to that StackOverflow answer there's nothing to control the aliasing, you'd have to write things pixels by pixels using some aliasing algorithms (I used one once for grid based line of sight...)

    So well... you'd have to either tweak the plugin to just do that, or find a way to draw polygons directly with gl calls (probably sending the vertices composing the polygon on the gpu directly, and since it only accepts triangles, as far as I remember, you would also need a triangulation algorithm... there's one in the box2D/physics plugin I think, for collisions... but yeah it would be a lot of work and I don't remember what C2 is exposing to help you on that... And that's why I choosed the easy road)

    And even with that, I'm not sure where C2 activate or deactivate antialiasing for WebGL if it ever does it (I think it does when you choose point sampling... yeah long time no C2 :D)

    So yeah, no easy answer on that one, sorry...

  • newt I dunno, maybe a pizza or a burger somewhere close by, my fridge is quite empty today.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmmm...

    edwardr

    Are you sure you didn't do more than just updating?

    'cause, I already see something wrong here:

    C:\Program Files\Construct2\exporters\html5[b]behavior\json-v1.1

    the .js and .ico files of the plugin are supposed to go in

    C:\Program Files\Construct2\exporters\html5[b]plugins\json\</p>

  • CrazyVulcan

    As big as your browser/device can handle (:

  • CrazyVulcan

    That's because C2 expects a string, a string in C2 is some characters (or none) surrounded by double quotes (")

    Problem is, what happens if you want you string to contains double quotes?

    Answer: you need to escape them.

    How to escape them?

    some languages use \" C2 use double double quote ""

    As a small remark, C2 isn't THAT weird in this area, you also do that if you want to escape double quotes in verbatim string literals in C#

    http://stackoverflow.com/questions/1928909/can-i-escape-a-double-quote-in-a-verbatim-string-literal

    Now, one way to avoid this messy escaping is to put your pretty json inside a file you import in the project, and you get retreive it using Ajax.

  • locohost

    from memory I'd say:

    JSON.Value(0, "units", 1, "unitID")
    JSON.Value(0, "units", 2, "qty")[/code:1w7j9ogo]
    
    the arguments are to be read as:
    1st: 0 = root, 1 = current  (current is used un foreach loops and I think you also have an action to set it)
    2nd: "units" is one of the key of your root object's member (if the root were an array , you would use the index)
    3rd: the index of the "units" array
    4th: "unitId" or "qty" one of the key of one of the object in the "units" array
  • zatyka

    yeah I'll probably release the fix someday, but I had started implementing object references to give a bit more power to the plugin, but got stuck with how to import/export references using JSON.

    I found some possible solution from dojo where they have a specific syntax for references but I didn't have time to really wrap my head around that to extract what I need from dojo (I really don't want to add dojo to the plugin just for their JSON functions)

    So, yeah... someday :D

    I could just release a fix on the array bug, but.... sadly... I'm not using version control so... <_<

  • Looking at your JSON, you have an array of objects with two keys, "score" and "show"

    So to get the score of the first object, you can do it like this:

    JSON.Value(0,0,"score")[/code:9b1y66wd]The first 0 means "from root", the seconds means, "first element", and then "key score"
    
    in javascript it would correspond to [code:9b1y66wd]root[0]["score"][/code:9b1y66wd]
  • Whyser

    well, remember you can also do:

    Load JSON " {
      ""someText"":""Hello World"",
      ""location"": {
          ""latitude"":"&mylatitude&"
          ""longitude"":"&mylongitude&"
       }
    }" at 

    rootygy@[/code:3twjem51] And trust me, I recently made a manhattan distance algorithm for strategy game prototype using this JSON plugin, and having the plugin spitting out warnings was a big help. I had forgotten some checks and looping through empty data. Without those warning the data would have been wrongly, automatically filled and I would have had very hard to fix bugs. You have to like "[url=http://stackoverflow.com/questions/2807241/what-does-the-expression-fail-early-mean-and-when-would-you-want-to-do-so#answer-2807375]failing early[/url]" (: @grossd that's an idea, I'll think about it thanks =)

  • Whyser

    Yup, it's not a bug, it's done on purpose, you should first manually create an object before filling it with property/value pairs.

    I prefer it not to be done silently

    Following your idea, I should check if an argument is a string or a number because

    set "Hello World" at root@"0"[/code:2205ryy3]it should automagically do[code:2205ryy3]var root = {};
    root["0"] = "Hello World";[/code:2205ryy3]
    
    Whereas[code:2205ryy3]set "Hello World" at root@0[/code:2205ryy3]it should automagically do[code:2205ryy3]var root = [];
    root[0] = "Hello World";[/code:2205ryy3]
    
    And I think that's messy and error prone.
    
    So basically your code should look like:
    [code:2205ryy3]Clear root@
    Set New Object at root@   // so the clear isn't necessary
    Set "Hello World" at root@"someText"
    Set New Object at root@"location"
    Set 10 at root@"location","latitude"
    Set 20 at root@"location","longitude"[/code:2205ryy3]
    
    it's equivalent to the javascript:
    [code:2205ryy3]root = {};
    root["someText"] = "Hello World";
    root["location"] = {};
    root["location"]["latitude"] = 10;
    root["location"]["longitude"] = 20;[/code:2205ryy3]
    
    so yeah bottom line, the json plugin shouldn't automagically create objects for you.
    if I'm not wrong, if you try inserting a property/value and the object doesn't exist, you should get the following warning in the console:[code:2205ryy3]invalid path: root@someText[/code:2205ryy3]or[code:2205ryy3]invalid path: root@location[/code:2205ryy3]
    
    This "invalid path" warning allowed me to debug some wrong code many times and I think silencing it would be a mistake. Yes you have to write more actions, but at least you stay in control of your datastructure.
    And events using the JSON plugins can get quite messy, 'cause construct2 doesn't have a lot of possibilities UI-wise. (I wish you could use the bracket notation)
    
    Hope I make sense.
    
    In any case you can rip apart my plugin to your heart's content :D  after all it's still in "beta" and if you find good ideas I'd be glad to add them.
    
    But keep in mind I have a more advanced version on my computer since more than a year, but I haven't released it because it's incomplete. I wanted to be able to have references to other object to avoid having to copy things and be able to create fun things like cyclic datastructures.
    But it's breaking the JSON serialization so you wouldn't be able to save/load the object's state properly.
    I found something from the dojo framework that might be a solution (they have a JSON.stringify that support references) but I didn't have time to rip it apart to just get the usefull bits (I wouldn't want to include the whole dojo library for just a plugin)
    (that's the current state of things concerning this plugin :D)
Yann's avatar

Yann

Member since 31 Dec, 2010

Twitter
Yann has 5 followers

Connect with Yann