Set id for variables in array

For questions about using Classic.

Post » Mon Dec 26, 2011 5:18 pm

Hi.

I have some problems with array. There is one-dimensional array with 10 variables. Variables are random and they change every tick. Is there any way to set up id for each of the variable? In result I need situation in which randomness of the variables will not affect the id number and id 1 will always be the lowest, id 2 second lowest and so on.

Thanks.
B
3
G
1
Posts: 12
Reputation: 499

Post » Mon Dec 26, 2011 6:08 pm

I'm not sure I understand your question... what is wrong with array indexes?

The first array cell is always at 0 index, the second at 1 and so on until the last cell with index of 9.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Dec 27, 2011 4:23 pm

0--1--2--3--4--5--6--7--8--9     Index
-----------------------------
56-82-31-66-23-15-08-42-11-18    Variable (random)
08-10-06-09-05-03-01-07-02-04    ID

On second tick variables will change their values in random order.

0--1--2--3--4--5--6--7--8--9     Index
-----------------------------
89-61-49-92-35-37-86-39-12-64    Variable (random)
09-06-05-10-02-03-08-04-01-07    ID

ID of variables will change according to values, but variables would not change their position in array.
B
3
G
1
Posts: 12
Reputation: 499

Post » Tue Dec 27, 2011 9:11 pm

0--1--2--3--4--5--6--7--8--9     Index
-----------------------------
89-61-49-92-35-37-86-39-12-64    Variable (random) ArrayA
12-35-37-39-49-61-64-86-89-92    Variable (sorted) ArrayB
09-06-05-10-02-03-08-04-01-07    ID ArrayID

+ ArrayB: For each element
++ ArrayA: For each element
+++ ArrayA: Value at ArrayA.CurrentX Equal to ArrayB.CurrentValue
---> ArrayID: Set index ArrayB.CurrentX to ArrayA.CurrentX

1) Array indices in Construct are 1-based (first index is 1)
2) Copy ArrayA to ArrayB after having generated the random numbers and sort ArrayB. A simple bubble sort algorithm will do.
3) After setting ArrayID, it will look exactly as pictured above. You now have a double reference (both index and ID) and can find either the ID from a value, a value from an ID, an index from an ID, an ID from an index, an index from a value or a value from an index. Just peek at the right positions of the appropriate arrays.
4) The events posted above will only work, if the random generated numbers are unique! 3-1-7-4 will work, 3-3-4-4 will not.tulamide2011-12-27 21:13:09
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests