Plugin suggestion one dimensional array

Discussion and feedback on Construct 2

Post » Mon Dec 05, 2011 3:26 am

OK, yeah it sounds silly, but my idea, or twist is a vector, or a x,y value for each index in the array, rather than the opposite a single value at an x, and y position like in the regular array object.
Something like getx, or gety at index in onedimensionalarray.
Much better way to keep track of a bunch of positions imho.

Of course you would also want set x,y, as well as set, and get length of index, etc.
Anyway its kinda like the datastructures plugins of both Cc, and C2, just with the ability at have two values.

Any thoughts, and or takers?
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon Dec 05, 2011 11:43 am

Newt, just to clarify, are you saying instead of doing this:

     Array(x,y) = i

You want to be able to do this:

     Array(i) = (x,y)
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Mon Dec 05, 2011 3:38 pm

Do you mean using the (y*w)+x formula for 2D access in a 1D array? What is the advantage of that over just x and y?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Mon Dec 05, 2011 4:49 pm

@Wastrel
The second, with exception that C2 doesn't handle arrays in expressions, so you wouldn't want to get both values at once, unless you were doing something like setting text.

@Ashley
Im not familiar with that formula, so I cant say for sure.
What it does offer is an order, say for example a path.

-+ for n = 0 to 1dimensionalarray.length
->sprite set x to lerp(sprite.x,1dimensionalarray(loopindex("n")).x,something*dt)
->sprite set y to lerp(sprite.y,1dimensionalarray(loopindex("n")).y,something*dt)

Course you would use some kind of timer with that as well, but you get the idea.
-+every n seconds set global.value("tcount")to clamp(global.value("tcount")+1,0,1dimensionalarray.length)
->sprite set x to lerp(sprite.x,1dimensionalarray(global.value("tcount")).x,something*dt)
->sprite set y to lerp(sprite.y,1dimensionalarray(global.value("tcount")).y,something*dt)

Or just something to sort things to predetermined positions:
-+For each sprite
->Sprite set x to 1dimensionalarray(loopindex).x
->Sprite set y to 1dimensionalarray(loopindex).y

To do stuff like that using the regular array is not real straight forward, as you would have to do a Boolean comparison, like is value at array(x,y)= 1, do stuff.
Problem is when doing it that way, its not easy to get the order straight.newt2011-12-05 17:00:52
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon Dec 05, 2011 5:49 pm

Can't the array object be used just like that?
Set the size to say (100, 2) for one hundred pairs of numbers.

(n, 0) would be the x's and
(n, 1) would be the y's.

Ex:
-+For each sprite
->Sprite set x to ArrayAt(loopindex, 0)
->Sprite set y to ArrayAt(loopindex, 1)

And if you later want an angle to be included set the array size to (100, 3) and (n, 2) would be the angles.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Mon Dec 05, 2011 6:07 pm

[QUOTE=R0J0hound] Can't the array object be used just like that?
Set the size to say (100, 2) for one hundred pairs of numbers.

(n, 0) would be the x's and
(n, 1) would be the y's.

Ex:
-+For each sprite
->Sprite set x to ArrayAt(loopindex, 0)
->Sprite set y to ArrayAt(loopindex, 1)

And if you later want an angle to be included set the array size to (100, 3) and (n, 2) would be the angles.[/QUOTE]

Yeah, that would work.
What would be nice though, is to add the functionality like a stack, where you can push, or pop values to certain places, like.

-+ sprite set x to 1darray getTop.x
-+ sprite set y to 1darray getTop.y
-> 1darray popTop

You can do that with Array, but for ease of use, the stack method would be pretty sweet.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon Dec 05, 2011 6:13 pm

The plugin newt is suggesting is indeed useful and also already exists:

check this out

Have been using it in a couple of test projects and it works great. Magistross did a great job on this!
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Mon Dec 05, 2011 6:28 pm

[QUOTE=PixelRebirth] The plugin newt is suggesting is indeed useful and also already exists:

check this out

Have been using it in a couple of test projects and it works great. Magistross did a great job on this![/QUOTE]

Yeah it works nice, but you have to use getToken in order to do two values in one object, and I'm not sure how much how much the text conversion would slow things down.
In Cc you could pile on hundreds of values, but eventually the conversion would slow things down, but In C2, you cant do a whole lot of positions, because its slower, so the conversion may, or may not be an issue.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon Dec 05, 2011 6:34 pm

[QUOTE]Yeah it works nice, but you have to use getToken in order to do two values in one object, and I'm not sure how much how much the text conversion would slow things down.[/QUOTE]

I'm kind of slow today. I don't get for what exactly you want to use getToken, could you please clarify?

Do you mean storing two values in one array element? Why not simply use two elements? Yeah, slow today...PixelRebirth2011-12-05 18:35:17
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Mon Dec 05, 2011 6:50 pm

[QUOTE=PixelRebirth] [QUOTE]Yeah it works nice, but you have to use getToken in order to do two values in one object, and I'm not sure how much how much the text conversion would slow things down.[/QUOTE]

I'm kind of slow today. I don't get for what exactly you want to use getToken, could you please clarify?

Do you mean storing two values in one array element? Why not simply use two elements? Yeah, slow today...[/QUOTE]

You got it, one element/ object. So it would be something like getToken((datastructures.top),1), for x, and getToken((datastructures.top),2) for y.

Your not slow, I'm just lazy.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Solomon, zenox98 and 9 guests