I want my app to stop cloning under certain circumstance

Hello all,

Me again. So the good news is I went back to square one with my chess app following discussions on here with a few of you. I am now using any components blocks and cloning buttons to help speed up the building phase and hopefully gameplay.
I have figured out how to get the rook to act as I want it to for movement. I am confident I can get the bishop, queen, king and pawn to act appropriately. Haven’t tackled the knight yet as I think that may take a little mind bending to figure out. Then again it might turn out one of the easiest. Who knows with coding?

Anyway, I have ran into another small problem. Attacking. I can get the rook to attack if only one piece is on the board. However, if there is another piece in front of it my game completely ignores this and looks for the piece behind (the original piece). It’s definitely an issue with how I have coded it but I can not figure out what.

I will attach a screenshot below of some of my blocks. Let me know if better ones are needed or ones with more detail. A bit of background to how I have coded it; I have asked the program to detect the hidden text on the piece clicked using the any components block. If the piece clicked contains the text BR (Black Rook) then display the “move” button and clone it 7 times. I made a function for this with an input value called numberOfLoops. Then attached the value 7 to that. In the function I have asked it to detect whether the clone’s x and y is the same as WP1’s x and y. If it is then the clone’s visibility should be false as should the move button. This is so it does not show anything after this as a possible move. This works fine. I have also used the same method to detect the top, bottom, left and right side of the board.
I then ask the loop inside the function to show another button called “attack1” if it detects that “clone” is at WP1’s x and y. The issue I have is introducing another piece. I want the app to show only the closest piece as an available attack no matter which piece that is (for example whether WP1 or WP2). Does that all make sense?

[EDIT] I have just discovered a way to remove the need for attack buttons. I have asked it to change the background image and text of the clone when it is at an enemy’s x and y instead of displaying a whole new button. I then ask it to change back after this. But I may still have the issue regarding it stopping cloning once it shows the attack button.

I may have resolved this myself. Please look at my blocks below and tell me if it’s overkill or if there is a simpler way. This code works for what I want to achieve. But is 4 different “if” statements for one move too much?

Don’t worry I figured it all out. I have drastically cut down the amount of coding used to just one if statement per chess piece.

I am now trying to work out a way to cut it down to one if statement for all pieces. I have a theory but can’t make it work right now. I want to get Thunkable to detect if there is any button at a certain x and y when a piece is selected. If it detects a button I want it to read the buttons text (of which will not be readable as I have hidden it). If it reads that it is a “black” piece - or the same colour as the selected component - then it should stop displaying the cloned move buttons. If it is an opposing colour then it should change the cloned move button into a cloned attack button (same button just with a different background and text so that I can code an attack).

Should I make a new thread for this or does it count as same issue?

Hello @sammy-wrightcuhb
Glad that you find a solution.
Clone is an advanced component so is better to create a new thread and share exactly what you are trying to build if it has to do with different components.

Based on the description you shared, I would suggest using a variable and setting that variable to true when the condition you described happens(create a black” piece - or the same color as the selected one).
This way you will need to check the value of the variable and when is true to do something different as you said (change the cloned move button into a cloned attack button).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.