Author Topic: Getting the ID of a brick above the other.  (Read 628 times)

How do I get the ID of other bricks touching the current brick?

How do I get the ID of other bricks touching the current brick?

%brick.getNumUpBricks() will tell you how many are connected on top, %brick.getUpBrick(%i) returns the i-th connected brick. So you'll need a loop to get all of them.

You can also call %brick.dump() to see all the variables and methods for it, for similar problems in the future.
« Last Edit: February 24, 2016, 06:46:19 AM by Zeblote »

%brick.getNumUpBricks() will tell you how many are connected on top, %brick.getUpBrick(%i) returns the i-th connected brick. So you'll need a loop to get all of them.

But how will I get the ID of the one right above? it always returns '0'

But how will I get the ID of the one right above? it always returns '0'

If it returns 0, there's no brick above it. Take a screenshot of your bricks and post the code you're using

If it returns 0, there's no brick above it. Take a screenshot of your bricks and post the code you're using

Never mind, I feel stupid. Made a mistake. Put 1 instead of 0. Thanks!

Indexes in almost every code ever starts with 0.
So in this situation getUpBrick(0) would return the first brick.

Never mind, I feel stupid. Made a mistake. Put 1 instead of 0. Thanks!
caught that ninja

« Last Edit: February 24, 2016, 07:03:25 AM by BloxersPost »