Array Events

For questions about using Classic.

Post » Mon Jan 07, 2008 6:35 pm

How would I go about making a sheet that checks if ANY variable in the array has a specific value and then does something based on this variable that has this specific value?
B
2
S
1
G
4
Posts: 33
Reputation: 1,266

Post » Mon Jan 07, 2008 6:51 pm

Suppose you want to perform an action on every element which equals 77.

Use the conditions:

+ Array: For Each Element
+ (System/Compare values) Array.CurrentValue equal to 77
: Any actions you want

For example, to limit all elements in the array to a maximum of 100 when the user presses spacebar:
+ On spacebar pressed
+ For Each Element
+ Array.CurrentValue greater than 100
: Array: set value at X,Y,Z:
Array.CurrentX
Array.CurrentY
Array.CurrentZ
to 100.

'For Each Element' repeats the event for every element in the array. Under the 'For each' expressions you'll find Array.CurrentValue (the value of the current element being tested), Array.CurrentX, Array.CurrentY and Array.CurrentZ (the indices of the current element).

Does this help?
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Mon Jan 07, 2008 7:06 pm

Aw, man, you made my day :D. Construct is a bit hard for me to grasp, but I'm learning! I really really love this tool. Many thanks for the fast respone :).
B
2
S
1
G
4
Posts: 33
Reputation: 1,266

Post » Mon Jan 07, 2008 7:19 pm

Hm, now I have another problem. I have:
+ Array: For Each Element
+ (System/Compare values) Array.CurrentValue equal to 1
: Create Object blahblah...
Even though the value isn't 1 or any other number, many many instances of this object are created. Help?
B
2
S
1
G
4
Posts: 33
Reputation: 1,266

Post » Mon Jan 07, 2008 7:33 pm

Well your event is equivalent to:

+ Always
+ Array: For Each Element
+ (System/Compare values) Array.CurrentValue equal to 1
: Create Object blahblah...

i.e., 'For Each' on its own runs every frame, not just once.
To resolve this add another condition above the 'For Each' condition. In my original example, I added a 'On spacebar pressed' condition above the For Each, to avoid this problem: the array is only checked when you press spacebar.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Mon Jan 07, 2008 7:40 pm

This is a another problem I just solved. Bur I mean something different:
+ On Layout Start
+ Array: For Each Element
+ (System/Compare values) Array.CurrentValue equal to 1
: Create Object at CurrentX*32 and CurrentY*32
What this should do is find all 1s in the array, multiply the X and Y values with 32 and place the object on a generated grid. But it does not only put objects where a 1 is, it puts objects everywhere on the grid and fills it up. It does not matter what number is in the array... I really apreciate your help :).
B
2
S
1
G
4
Posts: 33
Reputation: 1,266

Post » Mon Jan 07, 2008 7:49 pm

Oops, a bug! Something is wrong with For Each Element. I'll try have it fixed for the next build, which should be out today or tomorrow.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Mon Jan 07, 2008 7:51 pm

Thanks, I'll impatiently wait :D.
B
2
S
1
G
4
Posts: 33
Reputation: 1,266

Post » Tue Jan 08, 2008 2:05 am

I think I've fixed this now, when the next build comes out let me know if it works!
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests