Yann's Recent Forum Activity

  • Dasat

    hmmm

    but when i set the key or value to a defined variable in my program or content of some array, it doesnt reflect

    Not sure I understand what you are trying to say.

    + System: on start of layout
         Local text myKey = "someKey"
         Local text myValue = "someValue"
         -> JSON: new Object at root@
         -> JSON: set myValue at root@myKey[/code:2s2jgc8y]
    Doesn't work for you?
  • chrismaliszewski

    if you have an Array whose AsJson gives you

    {
        "c2array":true,
        "size":[3,2,2],
        "data":
        [
            [ 
                [10,32],[12,48]
            ],
            [
                [72,26],[80,32]
            ],
            [
                [-28,16],[-22,20]
            ]
        ]
    }[/code:3djezfzp]
    What would you want to transform it into?
    
    (or maybe use your own example, mine uses just random numbers)
  • JordanKal

    probably, but I won't make an example capx because it's a bit more complex.

    In my case the cutting was just done by choosing two vertices. With your idea you'll have the possibility to make cuts my selecting two vertices but also, three, four.... probably more.

    So not only will you have to keep track of the possible cut remaining, but also if the piece is already cut or not.

    for example, with your idea you could do:

    * * * *
         /
    * * * *
       / /
    * *-* *
    
    * * * * [/code:24wd54lm]
    but not
    [code:24wd54lm]
    * * * *
     \   /
    * * * *
       X   
    * *-* *
    
    * * * *[/code:24wd54lm]
    (at least you shouldn't be able to I think)
    On top of that you'll have to resolve vertices orders for the newly created polygons.
    So not impossible, but yeah hard.
  • istavang

    This plugin can load any json file that respects the json format described here: http://www.json.org/

    after that, what you do with the data is up to you =)

    (that's quite a quote you did there)

  • Ldk

    what's called snapping is just rounding off values, you can do it by events. More around here

    And, yes you can use solid behaviors.

  • Ashley

    Ah! indeed "clean" shows the error and if you "save", tizen will generate a new ID and fill the properties for you.

    For a first version it's ok, but the problem is that when you want to update the game you put in the store, you will need the same package ID.

    Otherwise the store system doesn't allows you to upload the binary.

    You'll have to either copy/paste the ID back into the config.xml or delete/create the app you uploaded on the store.

    I think construct2 should generate this ID. Maybe by simply hashing the project ID or just use java type package if possible.

  • troublesum

    Nope, I wouldn't have (:

    My post had more purpose than just to correct you affirmation.

    By going a bit more in-depth into how array works on a lower level, I aimed at offering another perspective on arrays on general. Since it's the main topic. You just gave me a pretext and a starting point.

    I think some misunderstanding about C2's array comes from what they try to emulate (multiD-array) vs what people are, nowadays (mostly with php and javascript), used to (array of arrays).

    Also, I believe that sometimes, digging further in the complexity, makes the current problem simpler by contrast (: ... works sometimes...

    Oh and I won't lie. I like to show off sometimes :D

  • troublesum,

    The way arrays usually work in all programming languages is they are dynamically referable locations of memory. IE. Each level can be accessed by "string" name or variable.

    NOPE[/code:1l4lru5h]An array, in traditional programming language (C/C++/C#, Java, Python,...) is a list of contiguous elements of the same size (in memory). No more, no less. 
    When saying "dynamically referable location" you probably mean that you can use a variable that can dynamically change to access any part of the array. And that's right.
    However, you can access each element using an integer index. Not a string, only an integer.
    
    For example, let say we have an array of 4bytes integers.
    In C (let's get back to the bare basics) you would do[code:1l4lru5h] int myArray[10]; //create an array of 10 ints[/code:1l4lru5h]
    This will exactly reserve 4*10 = 40bytes of memory.
    if we were to represent the array in memory, we could imagine something like that:
    [code:1l4lru5h]
    indices :   0    1    2    3    4    5    6    7    8    9
    schema:    [int][int][int][int][int][int][int][int][int][int]
    offsets  :  0    4    8    12   16   20   24   28   32   36   40 ...
    [/code:1l4lru5h]
    So how does an array work its magic?
    when you do myArray[7], the computer knowing that all element have 4bytes will look at the 7x4th byte from the start of the array
    And indeed the int at index 7 is the one at the offset 28 byte.
    
    That's how array works. No more, no less.
    
    Now, there's something that might confuse people depending on how you use arrays in some programming languages.
    
    [h2]Multi-dimensional arrays  ARE NOT array of arrays![/h2]
    
    A Multi-dimensional array is just an arithmetic trick. In memory, it's still a single line of contiguous data. However an Array of Array is an array of pointers to arrays spread over the memory.
    In C, you declare a 2-dimensional array like this:
    [code:1l4lru5h]int multiArray[2][3]; // initialise a 2D array. For clarity let say it has a height of 2 and a width of 3[/code:1l4lru5h]
    here is what it looks like in memory:
    [code:1l4lru5h]
    indices1:   0    0    0    1    1    1  
    indices2:   0    1    2    0    1    2
    schema:    [int][int][int][int][int][int]
    offsets:    0    4    8    12   16   20   24...
    [/code:1l4lru5h]
    if you want a value at index [1][2]  you get the value at offset (indice1 * width + indice2) * size_of_int  = (1 * 3 + 2) * 4 = 5*4 = 20
    
    Now an array of array, in C is declared like this:
    [code:1l4lru5h]int* arrayOfArray[3] // array of pointers to int. Or, for simplicity's sake: array of arrays of ints[/code:1l4lru5h]
    The special character* means pointer to what is before it.
    It means that you don't have an array of ints anymore, but an array of pointers to an int (yeah those iffy pointers is why people don't like C/C++). 
    For this short explanation, you just have to understand that an array of ints is under the hood a pointer to an int (the first of the array then you use the previously mentionned offset to traverse your memory). Then you can understand that as "array of pointers to an int", or more conceptually "array of arrays of ints"
    in memory, it looks like
    [code:1l4lru5h]
    indices :   0     1     2    3    
    schema:    [int*][int*][int*]
    offsets  :  0     4     8    12...
    [/code:1l4lru5h]
    (yeah pointers often also take 4 bytes but it depends on the compiler)
    
    So when you do 
    [code:1l4lru5h]arrayOfArray[2][/code:1l4lru5h]
    You basically get an array of int.
    Obviously C allows you to get any value in this array as well, so you can do something like
    [code:1l4lru5h]arrayOfArray[2][3][/code:1l4lru5h]
    But what happens isn't the same as with the 2D array. Here you don't do arithmetics per se, you directly go to were a second array of int is,  and use it directly like a simple array. A bit like Matryoshka doll  or like following a path.
    
    One of the main differences between the two, in practice, is that the arrays of your array of arrays can have different sizes (jagged arrays). It allows you for example, to build triangular matrices.[code:1l4lru5h][[3,2,1],
     [2,1]
     [1]][/code:1l4lru5h]
    Using a multi-dimensional array, You you just always have the same width, height, depth,...  So it's a good fit for square matrices.[code:1l4lru5h][1, 0, 0,
     0, 1, 0
     0, 0, 1][/code:1l4lru5h]
    
    Small note about javascript:
    Arrays in javascript are very far away from C arrays. They actually aren't really arrays but objects that expose a behavior close to arrays. Nonetheless, you can't access their elements by strings.
    Also, "true" multidimensional array in javascript, and also php are impossible. People talking about multidimensional array in those language are merely refering to how they use it. But make no mistake, they are indeed Array of arrays in all case.
    
    C2 array object aims to emulate the behavior of a true multidimensional array, that's why your can't easily have jagged arrays.
    
    
    

    accessed by "string"

    What you were refering to is called by many names. "Hashtable","Hashmap","Dictionary","Records",...

    [rant]Basically it's a datastructure which allows you to access a value indexed using a hash.

    Well usually, you don't use the hash but something that can be hashed (let say for example,... a string).

    The hash will correspond to an index in an array of "bucket" (another kind of datastructure) which contains all value whose key have the same hash (hash collision).

    The corresponding value is then inserted in or retrieved from this bucket.

    A hashtable is slightly slower than an array. Since read and write require more computation. But it often doesn't matter.[/rant]

    C2 dictionnary is just a simple basic hashtable.

    This is the limiting factor of C2 where not being able build large complex structures like recursive functions or dynamic data algorithms (closed loop systems)

    You can build recursive function in C2.

    + Function: "factorial"
      + Function: parameter 0 <= 1
        -> Function: set return value to 1
      + else
        -> Function: set return value to Function.param(0) * Function.call("factorial",Function.param(0) - 1)[/code:1l4lru5h]
    
    Also, you can build complex datastructure as well with a few hacks, but since it involves passing and parsing JSON strings arround, it's very inefficient.  And yeah there's no easy way to create things like circular linked list. It's not impossible, but it would require building a whole set of function interfaces to access some data a certain ways to simulate memory references. And safe is to say that we would move toward crippling efficiency. C2 is slow enough :D
    
    I would advise to take a look at my [url=https://www.scirra.com/forum/plugin-json-import-export-generate-edit-inspect_t100042]JSON plugin[/url]. It's still in development but I'm using it at work and it simplify few things.
    
    At home I already implemented the hability to load/save objects by reference. So you will be able to create any cyclic datastructure you want. 
    But since I have no cool ways to save that as json for debugging or saving, I'm still looking for a good solution.
  • I had the same problem, the template of the config.xml seems out of date: Bug report

    One easy fix is just to put any package and id you want. It has to be a unique string amongst all the package on tizen store. You can either use the Java style (I didn't try but I don't see why it wouldn't work, unless a dot is prohibited in a package name)

    <tizen:application id="com.example.myapp" package="com.example" required_version="2.2"/>[/code:1v8f8q6v]or using some hash-like string[code:1v8f8q6v]<tizen:application id="oYjHXcOzlL.myapp" package="oYjHXcOzlL" required_version="2.2"/>[/code:1v8f8q6v]
  • Problem Description

    Hi, I'm building some WGT these days using Tizen SDK and I noticed C2 was generating config.xml with missing informations the SDK complains about.

    Mainly:

    <tizen:application id="1234567890.YourAppName" package="1234567890" required_version="2.2"/>[/code:29zx428n]
    
    source: [url=https://developer.tizen.org/fr/downloads/sample-web-applications/load-web-app-tizen-sdk/sample-config.xml-file?langredirect=1]Tizen Web Application config.xml file[/url]
    
    (Also on a side note, it would be nice if we had a list of  template [[keywords]] we could use if we want to tweak them ourselves... 
    And also... maybe... some way to  select custom template on export, since (I think) modification of the default ones are overwritten when we update C2....)
    
    [b]Construct 2 Version ID[/b]
    r171
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi Ashley,

    I'm working on a game using cocoonjs, and I had to use the CocoonJS.PromptKeyboard action.

    It's all working well on the device, but when testing on the computer basically nothing happens. Which is the expected behavior. But I think it would be nice to emulate this part like this:

        Acts.prototype.PromptKeyboard = function (title_, message_, initial_, type_, canceltext_, oktext_)
        {
            if(typeof cr_is_preview !== "undefined") {
                var text = prompt(message_, initial_); // maybe something to allow the layout to refresh before calling the prompt since it's blocking whereas the cocoon prompt isn't
                if(text !== null) {
                    input_text = text;
                    this.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnKeyboardOK, this);
                } else {
                    this.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnKeyboardCancelled, this);
                }
            } else {
    
                // original code
                if (!this.runtime.isCocoonJs)
                    return;
                
                var typestr = ["text", "num", "phone", "email", "url"][type_];
                
                CocoonJS["App"]["showTextDialog"](title_, message_, initial_, typestr, canceltext_, oktext_);
            }
        };
    [/code:2w354z8b]
    
    What dya think?
  • Yeah I do confirm, I remade the test with the exact same two events discribed above.

    To be more precise, I exported the project and hosted it as a canvas app embedded in a page.

    When I load the game the first time, I get Onready, but If I just F5, the OnReady isn't triggered (Ctrl+F5 sometimes triggers the OnReady)

    I believe the js being in the cache, it's loaded so fast that the call to fbAsyncInit is done before the call to the system OnLayoutStart.

    And I do believe that each OnCreate of each instances of object type are called before the OnLayoutStart so everything is initialized at this point, including the facebook API js added to the page. So the racing condition is quite possible.

    Arne 's solution seems ok to me

    ( Ashley maybe, if you end up modifying the plugin, you could also expose a bit more data in expressions, like the fbAppID ... For now I have to hard code the link the the apps' page (In which I have a like to unlock) for my share button, If I can access the ID directly in runtime I can generate it using events )

Yann's avatar

Yann

Member since 31 Dec, 2010

Twitter
Yann has 5 followers

Connect with Yann