Yann's Recent Forum Activity

  • Foxe92

    Yeah, you necroforophile.

    That's indeed a very old corpse you digged here. These days I tend to avoid such process. Because the string is usually tedious to make, so tedious to maintain and also the events to parse it are tedious to write. Not complex, but tedious.

    These days I just use my JSON plugin

    I find it clearer, easier to use and more versatile. Though I would still use the Array plugin for simple flat list and the Dictionary plugin for simple list of key-value pair.

    I use the JSON plugin when I want to load more complex datastructure and when I want to have something easy to read/maintain.

    For example I could have an array of monsters like this

    [ 
        {type:"orc", hp:50},
        {type:"demon", hp:100},
        {type:"slimy", hp:20},
        ...
    ][/code:17skam44] in a JSON and easily spawn them at random.
    
    Anyway, to answer your question, tokenat allows you to access a part of a string considering a specific character as a separator.
    For example, if you have a string like[code:17skam44]"apple, banana, pear, cherry"[/code:17skam44]if you do[code:17skam44]tokenat("apple, banana, pear, cherry", 2, ",")[/code:17skam44]You split the string into parts (tokens) using the coma as a separator, and you get the part of index 2 (counting from 0). So it returns "pear".[code:17skam44]0: "apple"
    1: "banana"
    2: "pear"
    3: "cherry[/code:17skam44]
    tokenCount on the other end gives you how many token you have in a string, using the given separtor[code:17skam44]tokenCount("apple, banana, pear, cherry", ",")[/code:17skam44]returns 4
    
    So using a clever loop you can easily fill an array[code:17skam44]-> Array: set size (0,1,1)
    + repeat tokenCount("apple, banana, pear, cherry", ",")
        -> Array: push tokenat("apple, banana, pear, cherry", loopindex, ",") to back[/code:17skam44]
  • Sorry if it wasn't clear, in the test I ran, sometimes, On ready wasn't triggered and Is Ready returned true on start of layout. I'll try to investigate. And if I can reproduce it I'll get back to you with more detail on my settings and a capx.

    I'm a bit new to the facebook app creation, maybe I did something wrong setting some parameters in the facebook dev stuff.

  • Problem Description

    The OnReady trigger will never be... triggered... if the facebook API is ready before the first call to the on start of layout.

    I believe it's because, in the runtime Runtime.prototype.trigger function, you're preventing any trigger to fire if the sheet isn't active yet

    Attach a Capx

    Since the facebook plugin depends on a facebook id and the example is very small, I'll just post an image

    Description of Capx

    Either trigger both console log action, or only the OnReady if the facebook API takes time to load

    Steps to Reproduce Bug

    • press F5 or Ctrl+F5
    • look at the console output

    Observed Result

    Kind of race condition.

    Expected Result

    Either:

    The facebook plugin call the window.fbAsyncInit before the start of layout

    which should result in the OnReady being triggered, or put on hold to be triggered just after the start of layout

    -> this is the problem

    Or:

    The facebook plugin call the window.fbAsyncInit after the start of layout

    In this case, the onReady not being true, the part in the on start of layout will not execute

    The OnReady is triggered

    -> this is already working as expected

    Of course, a simple thing to do for now would be

    Facebook: isReady
    System: trigger once
         -> do things[/code:10wumhtn]
    
    [b]Construct 2 Version ID[/b]
    r169
  • Ashley

    Yup, but keep a critical eye, I didn't thoroughly test all implication this would have with combining all possibilities. But since it's so small it should be ok =)

    Aphrodite

    Yeah I'm guilty of not usually checking the manual. I prefer directly go into the plugin's source so I understand everything that occurs under the hood.

  • Problem Description

    Ok... I know it can be viewed as a feature request more than as a bug per se.

    But I choose to report it as a bug because the modification is so small that it looks more like a design oversight than anything else.

    So here is the thing:

    You can't ask the anchor behavior to just anchor your object vertically OR horizontally, leaving the other axis alone.

    In my case, I just wanted a UI element to stick to the left border and keep using its default Y position.

    But in some scaling mode (like scale outer) the difference between window border and object position can change. Thus Unecessarily moving the object.

    And in any cases, I always wondered why the options between Left, Top, Right and Bottom edge were so inconsistent.

    Here is my simple fix:

    edittime.js

    @@ -76,8 +76,8 @@
     // new cr.Property(ept_combo,      name,   "Item 1",       description, "Item 1|Item 2|Item 3")    // a dropdown list (initial_value is string of initially selected item)
     
     var property_list = [
    [ul]
    	[li]new cr.Property(ept_combo,  "Left edge",        "Window left",      "Anchor the object's left edge to a window edge.",  "Window left|Window right"),[/li]
    	[li]new cr.Property(ept_combo,  "Top edge",         "Window top",       "Anchor the object's top edge to a window edge.",   "Window top|Window bottom"),[/li]
    [/ul]+   new cr.Property(ept_combo,  "Left edge",        "Window left",      "Anchor the object's left edge to a window edge.",  "None|Window left|Window right"),
    +   new cr.Property(ept_combo,  "Top edge",         "Window top",       "Anchor the object's top edge to a window edge.",   "None|Window top|Window bottom"),
        new cr.Property(ept_combo,  "Right edge",       "None",             "Anchor the object's right edge.",                  "None|Window right"),
        new cr.Property(ept_combo,  "Bottom edge",      "None",             "Anchor the object's bottom edge.",                 "None|Window bottom"),
        new cr.Property(ept_combo, "Initial state", "Enabled", "Whether to initially have the behavior enabled or disabled.", "Disabled|Enabled")[/code:2hkpntpj]
    
    [b]runtime.js[/b][code:2hkpntpj]@@ -95,7 +95,7 @@
            var bbox = this.inst.bbox;
            
            // Anchor left to window left
    [ul]
    	[li]if (this.anch_left === 0)[/li]
    [/ul]+       if (this.anch_left === 1)
            {
                inst.update_bbox();
                n = (layer.viewLeft + this.xleft) - bbox.left;
    @@ -108,7 +108,7 @@
            }
            
            // Anchor left to window right
    [ul]
    	[li]else if (this.anch_left === 1)[/li]
    [/ul]+       else if (this.anch_left === 2)
            {
                inst.update_bbox();
                n = (layer.viewRight - this.xright) - bbox.left;
    @@ -121,7 +121,7 @@
            }
            
            // Anchor top to window top
    [ul]
    	[li]if (this.anch_top === 0)[/li]
    [/ul]+       if (this.anch_top === 1)
            {
                inst.update_bbox();
                n = (layer.viewTop + this.ytop) - bbox.top;
    @@ -134,7 +134,7 @@
            }
            
            // Anchor top to window bottom
    [ul]
    	[li]else if (this.anch_top === 1)[/li]
    [/ul]+       else if (this.anch_top === 2)
            {
                inst.update_bbox();
                n = (layer.viewBottom - this.ybottom) - bbox.top;[/code:2hkpntpj]
    
    (To really really be complete, maybe adding "window left" and "window top" for right edge and bottom edge option, imagining some cases where the object it is assigned to would change size while still be anchored to it's opposite border window... why not? (:  )
    
    I could of course fork the behavior... but just for that it would be... sad.
    
    In any case, Ash, don't hesitate to throw this post in another part of the forum if you don't think it should be here =)
    
    [b]Construct 2 Version ID[/b]
    r168
    
    [b]Edit:[/b]
    Ok after a bit more fiddling, I realised that the plugin was using the first two edges constraint to position the object and the two last to stretch it... which is highly unintuitive I'd say.
    Using my fix, you'd have strange result if you do Top Edge: None + Bottom Edge: Bottom.  I thought first that the object's bottom edge would stick to its initial bottom position, but with the current implementation, it will just stretch the object vertically to keep the bottom edge at its initial bottom position.
    So ok, it might be a mix of feature request and design/conceptual bug report... A matter of opinion (:
  • zatyka

    Oh, my bad. Makes kind of more sense

    Though I my comment still stands.

  • zatyka

    I do agree that the plugin's interface is a bit clunky and I would have liked for it to be simpler and more straight forward. However, I wouldn't bet on a reworking of the engine anytime soon.

    Hopefully, I do think that with it, you can do everything you can do with a basic javascript object (well almost... you can't copy an object by reference... yet :3)

    In any case, the JSON plugin's topic is always opened for suggestion =)

  • vtrix

    First there's never been any JSON.Key(...) expression, with or without parameters.

    Getting the key at a specific path doesn't mean much thing, because the key would be the last part of the path you are setting.

    Key(0,"my","path") should return "path". Key(0) shouldn't return anything (although it's "root" in javascript, but this implementation detail needs to be hidden from the user)

    Mabye the only use I could think of is Key(1) that would return the last component of the CurrentPath, but you should already know it in your code somehow.

    The only place where you could be unable to know the CurrentPath is in the foreach loop, that's why CurrentKey is set here.

    Otherwise, Value(0,"my","path") is already returning the value at the given path, and Value(1,"my","path") as well but relatively to CurrentPath.

    The difference between v1.0 and v1.1 is just the addition of CurrentValue which is an alias to Value(1).

    The other change I made was to reset the CurrentPath to what it should be at the begining of each loop iteration, and reset it to what it was before the foreach loop when you exit it.

    I was thinking about providing an alias like ValueFromRoot("my","path") and ValueFromCurrent("my","path") to make things more clear (maybe someone has a better idea)

    So, to summarize, I fail to see where a `Key` expression would be usefull, and the `Value` expression already works as expected, isn't it?

    And as far as CurrentKey and CurrentValue goes I prefer them to be simple. They are more or less the equivalent of the Dictionary counterpart.

  • Try Construct 3

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

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

    thanks nice finding, I was doing

    delete array[0];[/code:1o8zrg4h]
    but this doesn't change the size of the array so javascript set it to undefined (which is transformed to null on export)
    I have to do [code:1o8zrg4h]array.splice(0,1);[/code:1o8zrg4h]
  • vtrix

    Well... The problem is a mix between javascript ambiguity, striving for simplicity (nice way to say laziness) and giving as much control as possible

    In javascript, you usually loop through array elements like this:

    for (var i = 0; i < myArray.length; i++) {
          // do things with myArray[i]
    }[/code:3sbiy7t4]
    and you loop through objects members like this:[code:3sbiy7t4]for (var m in myObject) {
          // do things with myObject[m]
    }[/code:3sbiy7t4]
    
    Thing is, in javascript arrays are also some kind of objects. So looping using a for-in works.
    However there are few differences.
      - With the first solution you have an index that increments. So expected ordering is ensured and you only explore the range between 0 and size-1
      - With the second you treat array indexes as object properties, so if you did weird things like adding a value to an array using a non positive integer (like -1) or a key as an index (c2 doesn't prevent that), you would, at least, be able to loop through it using For each property. However, if I'm not wrong the JSON exporting will just export the array part, so overall adding properties to an array should be discouraged)
      - If you skip array indexes, like for example set a value at index 10 on an less than 9-elements array, the first loop will allow you to loop through all the indexes from 0 to 10 (the inbetweens will return undefined and the JSON export will be padded with null), whereas if you use the second loop (for... in) you'll only loop through existing indexes (skipping the inbetweens)
    
    So my idea was to leave as much possibilities as the user might want (so internally choosed "for .. in") while avoiding confusion (there's only one type of loop)
    This way:
    [ul]
    	[li]If you want to loop through arrays like an object (for... in), use For each property[/li]
    	[li]otherwise, use a for/repeat loop like this:[code:3sbiy7t4]+ System: repeat JSON.Size(0,"path","to","array")[/li]
    [/ul]   -> Browser: log JSON.Value(0,"path","to","array",loopindex)[/code:3sbiy7t4]which is equivalent to for(var i = 0; i < arr.length, i++) {...}
    
    As for the necessity to cast currentKey to int... it's because I return currentKey as a string, I should probably return it as an "any" type (meaning string or number).
  • vtrix , shinkan (mostly highlighting you since you were the most active (: )

    New version: JSON v1.1

    The first post documentation has been updated to reflect this change

    ChangeLog

    v1.1 - 2014-04-17

      - implement save/load/debugger
      • ToJson deprecated and replaced by AsJson for overall coherence
      • change the brackets syntax for a less confusing one (I hope) before: root["Wizard","stats","hp"]
      after: root@"Wizard","stats","hp"[/code:2i4wuwdv]- change Length for Size and handle object/array return -1 for anything else
      • isEmpty condition and Clear action for array and object
      • add a CurrentValue property
      • in foreach loop reset the current path to the path given at the begining on each iteration, this way we can mess with this current path to our heart content within the loop
      • more reliable logData

    Have fun testing

    If all go well, I'll probably move it to completed plugin.

Yann's avatar

Yann

Member since 31 Dec, 2010

Twitter
Yann has 5 followers

Connect with Yann