Problem with "and" logic

Ok, so first off I’d like to thank this community for all the help. I definitely feel like I’m learning a whole lot more about how to use blocks thanks to the questions I have posed in here. My blocks have simplified in a HUGE way. However, it has caused other issues that I could fix before (all be it in a very time consuming way).
One of these issues is the “and” logic. I have included a screenshot of my blocks below. I will explain after the screenshot my goals:

So as you can see I am using ‘any button’ component. The bottom ‘if-do-else’ block is where I think(?) I’m having an issue. I have a button called M1 which when clicked will move button BP to M1’s x and y. It does this in the first ‘if-do-else’ block after clicking any button. Happy with that.
I want M1’s text to display as WPTR (White.Piece.To.Right) if another button called A1’s x can be found in app variable WPX and A1’s y can be found in app variable WPY. If it does not then it should just display “M1”. This does actually work as I would like it to.

The problem is it also displays WPTR when a piece is directly in front of it and not at A1’s x and y. I feel it is probably just detecting that app variable WPY does contain A1’s y and therefore it should display that message. I thought the “and” logic block should mean that message only displays if both the values are true.

Is there any suggestions?

Yes, the “AND” block only returns true if both conditions are true. Is there a chance that your list variables are not actually lists but are instead something like text strings?

One way to eliminated the “AND” block from the equation – for testing, although I’ve never had a problem with it – is to convert this:

if 1 AND 2

to this:

if 1
   change label's text to "condition 1 is true"
   wait 1 second
   if 2
      change label's text to "condition 2 is true"

Make sure the [if] blocks are nested, not stacked. Then preview the project and see if you see this:

condition 1 is true
condition 2 is true

If so, you know the AND block is doing it’s job and you’ll have to figure out why it keeps triggering when you don’t want it to (not that it’s faulty, but rather that your conditions are true when they shouldn’t be).

Yeah it appears the AND block is working as it should. Both conditions show true. So it’s clearly a case of I’m putting the conditions in wrong.

I think the issue may be simply that I’m asking if the app variable lists contain A1’s Y and X. Which I suppose they do. However, I only want it to display WPTR if there is an object at A1’s Y and X. I’ll keep working on it.

That makes sense. I think at a minimum, your database needs to keep track of – for each square on the board – row, column, piece. It looks like you’re using x and y for the rows and columns. So the “piece” value would be something like K for a King, Q for a Queen, etc, as well as “” (empty string) or any non-letter symbol you choose for an empty square.

to answer that question, you need to keep track of a 64-entry array to represent your 8x8 board - assuming we’re talking about chess -and each cell at board(x,y) should be able to indicate that it contains a “” (empty) or “WK” (white king), or “WQ” (white queen), etc… this is in addition to your array of pieces (which contain their current location at any one time) -you will need this if you want to want to answer questions like … can this black bishop move to that location and you have to ensure that there are no pieces on its path, etc.

1 Like

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