How do I shift array values

0 favourites
  • 5 posts
From the Asset Store
Design for game, asset for game, game kit, UI design, completed design for game, mobile game, Gravity Shift
  • Hello,

    I know people get mad when posting without effort, so just to let people know I've read the FAQ, and saw the post explaining this but the capx files didn't work. The other solution for some reason was a data struct plug-in. I'm just wondering is there an easy way to shift array values around in Construct. Construct would benefit so much from a simple move elements left 1 or move elements right 1 command. Also index swapping would be a huge benefit.

    How can I learn to do these two things easily with an array? It would help my programming immeasurably. Scripting would be a good inclusion to. Like JS scripts.

    The creators of Construct 2 could add a swap action under manipulation in a matter of half a day...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's not hard to do swapping yourself.

    Save the first of two values to a local variable (or dictionary, if you can't be sure about the type). Write the second value to the first position. Write the contents of the local variable to the second position.

    Not sure how exactly you wanna shift. Are we talking about about a one dimensional array or do you want to shift a 2- oder 3dimensional array? One dimensional should be easy with pop etc (though it might not be memory efficient with large arrays).

    If it's something you need regularly or often, you could make yourself a template maybe.

  • I see mindfaQ beat me to it... but maybe you missed the manual entry for Arrays

    https://www.scirra.com/manual/108/array

    You can use POP, and Push to shift values left or right, Insert or Delete, Reverse, Sort, lots of good things to do just what you want.

  • Hey,

    I just figure out how to shift the values. Basically I swapped first index with last, deleted the old first index. This creates a looping effect when set to a button. Now if I click left button the array values shift in a loop. Right button would be reverse order... now. I'm wondering something else. I need to move and object from a position to a specific position based on a array key, but all I can find is current value.. I need something a little more robust...

    Take a look at this image..

    This isn't exactly what I need. I need to say if current index 0 move sprite with the name of value to such and such a place. Then if index 1 move sprite with name of value to such and such a place.

  • Just wanted to show another image. If I append currentx to text I get 01 which seems to be right.

    I'm just so muddled. I know what I want, but not how to achieve it. I have an array of inventory items. I want to have an inventory grid where each square is the same as the elements of the array. So item at index 0 goes in the first inventory block, item at index 1 goes in the second..

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