Yann's Forum Posts

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 rootyet@[/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)
  • Ah! my bad (: I didn't update 'cause in 187 there's a potential breaking change and well... I don't have time to deal with it at work =), anyway that's neat, thanks.

  • Problem Description

    When you minimize the C2-ejecta application and go back to it, you get a javascript error about a null context

    This change fixed it:

    in the Audio plugin:

    +++ ...\exporters\html5\plugins\audio\runtime.js
    @@ -2726,7 +2726,7 @@
                 return;
             
             // upon resume: first resume the whole context
    [ul]
    	[li]if (!s && context["resume"])[/li]
    [/ul]+        if (!s && context && context["resume"])
                 context["resume"]();
             
             var i, len;
    @@ -2734,7 +2734,7 @@
                 audioInstances[i].setSuspended(s);
             
             // after suspend: also suspend the whole context
    [ul]
    	[li]if (s && context["suspend"])[/li]
    [/ul]+        if (s && context && context["suspend"])
                 context["suspend"]();
         };[/code:lm22brj0]
    
    For some unknown reasons, context might probably be null during a few frames and then the audio kicks in back.
        
    [b]Operating System and Service Pack[/b]
    iOS 
        
    [b]Construct 2 Version ID[/b]
    r186.2
  • Ashley, oh sweet thanks (:

  • Ashley ,

    Once again, this bug bit me today. So I thought of an alternative temporary solution: an option to deactivate spritesheeting on specific frame/animations/object/project. This way there's no need to manually post process the exported image each time (with the risk to forget). For now I can do that by setting the export format to JPG. But sometimes I still want transparency so it only works in some cases.

    Yet again, I think you should pad pixels when you spritesheet (which only happen on export right? not sure why you mentionned spritesheeting for preview). I don't see any problem with doing that, because you already have a margin between images, you only need to add a little processing to repeat the bordering pixels on each side of the image.

  • delgado

    now it's corrected puzzleDelgado.capx

    it wasn't an issue with C2 versions, just that the code was very wrong in a few places. (also I added a few simplifications)

  • Ashley

    You don't need to add padding at preview time, since you are not spritesheeting. The texture is probably using gl.CLAMP_TO_EDGE which has the same effect as padding pixels.

    The problem only arise when the image being sample is inside a spritesheet, which only happen on export (right?).

    If somehow you could change the spritesheeting algorithm to add 1pixel padding around the images on export, the problem would be solved.

    For now, I have to remember doing that myself on photoshop each time.

  • Problem Description

    I've notice a discrepancy between preview and export when rendering stretched sprites.

    This happens when your frame get "spritesheeted". And probably only when using webGL.

    This probably happends because when weGL renders the border of an image, it linearily interpolates with the neighboring pixel.

    To avoid this problem, in 3D games, we usually pad the pixels of a texture (repeat first/last rows/columns)

    Attach a Capx

    pixelPaddingOnExport.capx

    Description of Capx

    You should compare preview on export (I added a dummy frame on the sprite to force spritesheeting)

    Steps to Reproduce Bug

    • Preview -> notice that nothing is wrong, the 3 sprites are seamless
    • Export -> notice that there's a blurry seam on the sprites' sides (like in the editor)

    Observed Result

    Discrepancy between preview and export

    Expected Result

    Should behave like preview (no blurry edges)

    Affected Browsers

    • Chrome: YES
    • FireFox: YES
    • Internet Explorer: WHO CARES?

    Operating System and Service Pack

    Win 7 Ultimate

    Construct 2 Version ID

    r178 (and probably higher since I haven't see any mention of a fix in the changelogs)

  • Inc

    Nobody prevents you from posting your capx here (unless there's some forum limitation I'm not aware of)

    I'm not the only one who can help (:

  • Inc

    I just opened the original capx and played it, everything looks fine. Did you change anything? What you are describing would mean that xTarget and yTarget are equal to 0