Simplifying webstore, dictionary and array

0 favourites
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hello,

    I've labored the day of yesterday to get something rather simple to work, to display in a listbox, in a sorted manner, names stored in a webstore, and have a text entry field, add and remove button, to add and remove names in the list.

    It turns out to be complex due to a number of reasons:

    1. Only array supports a sort method. Without array I would need to program the sort.

    2. Array always starts with at least one "zero" element (dimension 1,1,1), which show up in the list, when transfering values from the array to the list

    3. webstore can only be conveniently loaded via json to a dictionary, so if i want it sorted, i have to transfer the dictionary to an array

    4. to delete selection items in a list from the webstore its necessary to either keep track of the key of each item in the list, or to use the name of the item in the list as ke

    5. there is a need to use loops extensively but there is no event that indicates when a loop completed, in order to continue the next step in processing

    All in all, a surprising difficult task to program

    Here are some suggestions to simplify this, perhaps Ashley might find some of interest:

    1. Ideally, like in other modern GUI environments, there could be a binding between elements in one list, such as the visual list and another list, such as elements in a web store

    2. alternatively, there could be a sort function on the Dictionary, treating the dictionary keys, like an array, as if it had some order, since the for loop, iterates through some predefined order

    3. having a for (sorted) that does the sorting for the dictionary, by key or value

    4. support a generic "asjson" that supports loading keys or values from a dictionary into another elements via json (e.g. from dictionary to array, from array to list). Currently there are limits on loading json from one element to another

    re: 4, here is one way the task could be accomplished with Json:

    1. Load json string of webstore items into an array

    2. sort the array

    3. load json string of the array into the list

    thanks,

    Dan

  • It doesn't make sense to "sort" a dictionary, since all keys are named. What you actually want to do is sort the array stored inside the dictionary, but since it's not a primitive, you end up having to copy it out into an array, sort it, and copy it back.

    The problem stems from the fact that you're "hammering in" an array as dictionary keys. This is not your fault, it's just the way construct's webstore works, due to the fact that the dictionary object can only store numbers or strings.

    In my opinion, we need Construct 2 to do two things:

    Start treating arrays (and dictionaries but that's another point) as primitives instead of as an object.

    Have a proper JSON parser where we can access deeply nested structures using javascript notation.

  • All stuff I have had to do with C2. However they require extra steps and annoying as hell. I agree that arrays need to be simplified and I would love for a JSON Object for data storing groups.

    However you can use R0j0hounds Hash which works as a JSON storage for now.

    Also Fimbul is right. Dictionary can't really sort. However you can itterate through Dictionary into an array. Then sort the array.

  • I'd like to point out that the hash plugin jayderyu mentions wasn't made by me. On another note, Yann has made a json plugin that may be useful.

  • 2. Array always starts with at least one "zero" element (dimension 1,1,1), which show up in the list, when transfering values from the array to the list

    I don't get it. An array of the dimensions 1,1,1 will have one element by default. Why don't you start with a width of 0 before you push stuff into the array? There won't be a "zero" element to transfer, as you put it. Or am I misunderstanding something?

  • R0J0hound

    hmm. maybe it's Rex's plugin then. My mistake

  • I would like to see someday visual array editor. Not that I'm not able to use them as they are now, but it would speed up the process a lot. Simple stuff, open array in editor and you see a grid and have several options to set the size, select grid and input txt ( like in excel spreadsheet) and then when wanting to specify expression i could use field picker and visually pick the field I want. That would be neat. But for now, the best way is to use external txt files.

  • Hi all,

    Many thanks for all those useful comments.

    Fimbul, jayderyu, indeed dictionaries don't by definition have a sorting order. However, you can have a method that returns keys or values in some sorted way, or to have an "iterator" that iterates through keys or values in a sorted manner, or returns keys or values as an array.

    I am not sure I understand why we need Array as a primitive. Is this a performance (processing, memory) consideration, or would offer cleaner programming concepts.

    PixelRebirth, the documentation states that arrays must have at least dimension 1,1,1, otherwise they don't work; and indeed they don't work if you set one dimension to zero. Why this is the case is unclear to me.

    Overall, i find the 3D dimension array object a bit confusing. It might have been better to have three types of array objects, a Array1D, Array2D and Array3D. Is there any benefit of having one Array objects that "servers" all dimensions?

  • jayderyu, and I forgot to mention -- indeed, I do iterate through the dictionary and insert values into an array. The issue I ran into there is that this iteration is only a first step in additional processing -- such as then sort the array, and transfer the array into the list.

    However, there is no direct way to know when the for dictionary loop has ended, i.e. no direct trigger that would continue the processing. This is my item (5) in the list in my initial posting of this thread.

    Instead, i used the exit condition (when array has reached the size of the dictionary) as the trigger (and trigger once) to do the next processing. It works, but it would be better to have an event that triggers when a loop ended.

  • grossd arrays work with 0 size , but i guess at least one axis should be size 1, not sure, i already used size 0,1,1 or 0,0,1

    if you then do a push on x-axis, first 0 value will be gone

    also if a loop has ended, it will autorun the next event, so just place a trigger or a function under the loop (not inside) would that not work for you?

  • Thanks vtrix, for the info. i tried an array of 0,1,1 and it didnt work, but perhaps i had something else not working. I'll check it.

    this "autorun" feature of an event or function after a loop statement, is this an official documented feature?

    it sounds contrary to the event sheet approach, where no sequence across event statements can be assumed.

  • An array must be at least size of 1 for each axis, if only one of them is 0, then you can't store anything!

    however, the array is 0 based, so the top-left-back position of a array will be (0,0,0), an array of size (3, 4, 5) will have (0 to 2, 0 to 3, 0 to 4), since from 0 to 2, you have 3 values (0 and 1 and 2), a 3x4x5 array can store 3x4x5 values (=60)

    Due to the same logic, an array with a size of 0 on one axis cannot store any data, since you can store 0 values at the end (3x4x0 =0)

  • Thanks Aphrodite,

    The problem with this setup (i.e. at least 1,1,1 dimension) is that location (0,0,0) is initialized to 0. When you then create a loop and use push x to add a value at dimension x, then its added at (1,0,0), leaving location (0,0,0) with the 0. In other words to "push" into location (0,0,0) requires special treatment via a new event or, the use of insertat instead of push.

    Dan

  • grossd , you cant set a value to an array that has 0 size, put pushing should work on a zero sized array, i make an example, but im still on r165

    i don't understand about the loop, if you run a repeat 10 times, after the 10 it continues, same for arrays for each or for each instance, if the loop is finished it continue's the events, so if you have an event with a subevent that loops, than under the loop you do you next action..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think a sub event is executed for each loop iteration.

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