Plugin suggestion one dimensional array

0 favourites
  • 10 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • 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?<img src="smileys/smiley4.gif" border="0" align="middle" />

  • 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)

  • 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?

  • 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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    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.

  • 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!

  • 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!

    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.

  • eah 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.

    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...

  • eah 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.

    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...

    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. <img src="smileys/smiley17.gif" border="0" align="middle" />

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