Simplifying webstore, dictionary and array

Discussion and feedback on Construct 2

Post » Sat Apr 12, 2014 7:41 pm

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.
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Sat Apr 12, 2014 9:32 pm

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)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Sat Apr 12, 2014 9:36 pm

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
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Sat Apr 12, 2014 10:18 pm

@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..
ImageImage
B
69
S
21
G
7
Posts: 827
Reputation: 10,017

Post » Sat Apr 12, 2014 10:25 pm

I think a sub event is executed for each loop iteration.
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Sat Apr 12, 2014 10:27 pm

https://dl.dropboxusercontent.com/u/61666915/zeroArray.capx

zeroArray example

i added an alert, the event after the loop (thats the same as the end of the loop)

a subevent of the loop will be executed every iteration, but an event with loop as subevent, you can still run another subevent that will not iterate
Last edited by vtrix on Sat Apr 12, 2014 10:30 pm, edited 1 time in total.
ImageImage
B
69
S
21
G
7
Posts: 827
Reputation: 10,017

Post » Sat Apr 12, 2014 10:29 pm

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


You seem to be saving each item in the list as a separate WebStorage value and then loading all of WebStorage into a dictionary to load it. It would be easier to keep the items in an array and save/load the array.
You do not have the required permissions to view the files attached to this post.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Sat Apr 12, 2014 10:48 pm

That's perfect. Thank you for the example and effort.

Indeed, i didn't think about adding the whole json list, in json, to webstore; but stored each value individually. Your solution is a great simplification because it avoids the need to use dictionary as intermediary.

Also, it shows that dimension 0,1,1 does work!.

Dan
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Sat Apr 12, 2014 10:51 pm

vtrix wrote:https://dl.dropboxusercontent.com/u/61666915/zeroArray.capx

zeroArray example

i added an alert, the event after the loop (thats the same as the end of the loop)

a subevent of the loop will be executed every iteration, but an event with loop as subevent, you can still run another subevent that will not iterate


BTW, It looks like this example uses a latest C2 beta version 165?, instead of the current official release 163.
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Sat Apr 12, 2014 11:03 pm

@ramones,

BTW, one side effect of storing the whole array in one webstore key is that duplicates need to be dealt with explicitly during add; but its very simply done, just by adding another condition: that the value entered is not already contained in the array.

again, many thanks,

Dan
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: tarek2 and 6 guests