[SOLVED] Problems building Rhombus-like board (based on Magic link tutorial)

Good day everyone!
My issue is that when I build board, visually it builds correctly, but the system thinks, that the first block in the bottom line is at position X = 0, but actually it’s at position X = 2.
See this screenshot.
Please, I need some help. I can’t find the source of the problem.

Here is my project’s structure:
Screenshot

Here are my script-files:
Board - board.script (6.8 KB)
Block - block.script (423 Bytes)
Connector - connector.script (646 Bytes)

Hello @BloodyReaper

Its hard to say whats going on since you cannot upload attachments because of your trust level.

Best Regards,

Thanks!
It turned out, that I have became a Basic User not so long ago. What a coincidence :slight_smile:
I’ve attached the script-files!

Hello @BloodyReaper ,

You are getting the wright position from input but are you sure that “self.board[y][x].id” position is 40,40 ? Couldn’t figure out how you handle empty cells in your table.

Best Regards,

Hello, @ArmandCloud ,
Thank you for answer!

I’m not handling empty cells in any way, I’m just skipping them in the “zero” loop in which I’m also finding X position:
apos = apos + 1
, it means that, if “zero” loop will go through 2 times, then “apos = 2” (which means that there are 2 empty cells) - and I use that variable by adding it to the X in the following “X” loop where I’m assigning x:
apos = apos + x

When I’m trying to print the marked block position it says:
DEBUG:SCRIPT: Marked block position = [240.000000, 80.000000, 0.000000]

X position here is 240 or 2 by id, which is right - But it gives me this message in the console ONLY if I click on the first empty cell, as I was mentioning in this screenshot - which is not right. And it should give me that message when I click on the actual block. I’m a bit confused.
How can I get right position when I use “go.get_position” ? Or, because I’m not handling empty cells it thinks that the “x” is actually located at “0” position?

Hello @BloodyReaper ,

Yes , i think (0,0) on your table mapped the first item . So you should mark position from your input ;

-- Mark block
				p =vmath.vector3(x*80 + 40,y*80+40,0)
				local id = factory.create("#connectorfactory", p, null, { color = self.board[y][x].color })
				table.insert(self.connectors, id)

I am not sure.

Best Regards,

1 Like

Well, it fixed the positioning of the marked icon. Now it shows right where you clicked :wink:
Here’s the screenshot.

But the problem still remains…
The block is marked only when I click on the first empty cell in the bottom line.
The same goes for the second line from bottom, the top line and second line from top.

Someone knows where the problem might be hiding? :disappointed:

I finally managed to find the problem. Thanks @ArmandCloud for your help too. With you help I was able to position the marker correctly!
How can I close the topic?
P.S. Sorry for the dumb question, I’m pretty new to this forum.

Hello @BloodyReaper ,

Maybe add [SOLVED] to your title works. And also sharing your last solution to your specific problem might good for new comers.

Best Regards,

1 Like

I’m very grateful for the help! Thanks again!

1 Like

(xkcd: Wisdom of the Ancients)

6 Likes

@jakob.pogulis Yeah, I know :slight_smile: I was at it!

The problem was in this code below:

for y = 0, 2, 1 do pos.y = 80 + blocksize * y self.board[y] = {} for zero = 3-(y+1), 1, -1 do posish = posish + 80 apos = apos + 1 end for x = 0, 2*(y+1)-2 do pos.x = 80 + blocksize * x + posish pos.z = x * -0.1 + y * 0.01 c = stones[math.random(#stones)] local id = factory.create("#blockfactory", pos, null, { color = c }) apos = apos + x self.board[y][x] = { id = id, color = c, y = y, x = apos } end posish = 0 apos = 0 end

If to be precise in this part of it, where you assigning “x” and “y” to the table:

apos = apos + x self.board[y][x] = { id = id, color = c, y = y, x = apos }

Let’s imagine this situation: In the first pass of the “X” loop -> x = 0 and when we try to map the values to the table it looks like that:

  • but apos here is 2, which is why the actual image of the block was located correctly (X = 2), BUT it’s “hitbox” was at X = 0.

All that we have to do here is to map the position we want. So, here’s the final correct code:

for y = 0, 2, 1 do pos.y = 80 + blocksize * y self.board[y] = {} for zero = 3-(y+1), 1, -1 do posish = posish + 80 apos = apos + 1 end for x = 0, 2*(y+1)-2 do pos.x = 80 + blocksize * x + posish pos.z = x * -0.1 + y * 0.01 c = stones[math.random(#stones)] local id = factory.create("#blockfactory", pos, null, { color = c }) x = x + apos -- In the first pass x is 0, then -> x = 0 + 2; self.board[y][x] = { id = id, color = c, y = y, x = x } -- self.board[0][2] = { id = id, color = c, y = 0, x = 2 } -- Now it is correct end posish = 0 apos = 0 end

2 Likes