Simplifying webstore, dictionary and array

Discussion and feedback on Construct 2

Post » Fri Apr 11, 2014 5:46 am

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
B
9
S
4
G
1
Posts: 210
Reputation: 1,391

Post » Fri Apr 11, 2014 5:52 pm

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.
B
36
S
8
G
8
Posts: 532
Reputation: 6,903

Post » Sat Apr 12, 2014 12:57 am

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.
B
92
S
18
G
9
Posts: 2,455
Reputation: 15,113

Post » Sat Apr 12, 2014 2:26 am

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.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Sat Apr 12, 2014 5:37 am

grossd wrote: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?
B
23
S
6
G
11
Posts: 1,047
Reputation: 8,065

Post » Sat Apr 12, 2014 7:16 am

@R0J0hound
hmm. maybe it's Rex's plugin then. My mistake
B
92
S
18
G
9
Posts: 2,455
Reputation: 15,113

Post » Sat Apr 12, 2014 5:37 pm

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.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203

Post » Sat Apr 12, 2014 6:36 pm

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?
B
9
S
4
G
1
Posts: 210
Reputation: 1,391

Post » Sat Apr 12, 2014 6:44 pm

@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.
B
9
S
4
G
1
Posts: 210
Reputation: 1,391

Post » Sat Apr 12, 2014 7:33 pm

@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?
ImageImage
B
71
S
22
G
7
Posts: 827
Reputation: 10,177

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Google [Bot] and 10 guests