[Solved] How to detect an object below him?

Get help using Construct 2

Post » Fri Jun 05, 2015 12:37 pm

What should my capx do?
Every Blok check if below him is a Blok. When there are none, the Blok will move down to his spot.
The challenge is how the Bloks knows if there is no Bloks below him.

What I have done
I have been using an array for this problem.
A set of Bloks has an RowID and ColumnID. These are used to insert value in the array.
If a Blok exist, he will set in the array at x=Blok.ColumnID,y=Blok.RowID as value=1

When a Blok got destroyed, the value in the array at x=Blok.ColumnID,y=Blok.RowID becomes value=0

Each Blok checks in the array at x=Blok.ColumnID,y=Blok.RowID+1 (the row below the current Blok), if this value is zero. The Blok will move down performing the following actions.
In the array at x=Blok.ColumnID,y=Blok.RowID value become zero
The row below will receive a value=1
The old RowID of the block will change to RowID+1

There after an event will snap these Bloks to the Nodes with the same ColumnID and RowID.

Problem
When you destroy many blocks in a short time. A bug will appear. It prevents Bloks from moving down or getting spawned. Value 1 are assigned to the array while there are no Bloks in that position.
Can someone explain me what is causing this problem? When possible, how can I solve it?
This can be solved by resetting the entire array to zero and putting in value=1 back in the array. This works, but it require many unnecessary "for each loops".

If there are others ways to do this, please let me know :D
I'm really having hard time figuring out what is causing this bug :cry:
Thanks in advance for helping :)

Here is the capx
https://dl.dropboxusercontent.com/u/15249798/C2%20how%20to%20move%20Bloks%20down.capx

Edit: Changed the title so [Solved] can fit in
Last edited by ikke2902 on Fri Jun 05, 2015 2:21 pm, edited 1 time in total.
It's time for me to return the favor :)
B
32
S
9
G
9
Posts: 132
Reputation: 5,370

Post » Fri Jun 05, 2015 1:52 pm

You are missing a "For each Blok" under your line 3 condition. If more than a block is destroyed in a tick, your array will start to desync with the actual grid.
B
74
S
31
G
26
Posts: 994
Reputation: 20,198

Post » Fri Jun 05, 2015 2:19 pm

You are amazing, that did the trick :D

Thank you very much!
It's time for me to return the favor :)
B
32
S
9
G
9
Posts: 132
Reputation: 5,370


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests