How do I shift array values

Get help using Construct 2

Post » Wed Aug 26, 2015 5:48 pm

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...
B
7
S
2
Posts: 92
Reputation: 663

Post » Wed Aug 26, 2015 6:23 pm

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.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Wed Aug 26, 2015 6:42 pm

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.
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Thu Aug 27, 2015 1:35 am

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

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.
B
7
S
2
Posts: 92
Reputation: 663

Post » Thu Aug 27, 2015 3:18 am

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

Image

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..
B
7
S
2
Posts: 92
Reputation: 663


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Nicolas951, R0J0hound and 11 guests