If then Statements

If I have a statement like the one below how do I repeat it for other spaces on the board? For instance if I want to say if (findBlock(1,1) == findBlock(1,2) == findBlock (1,3) and so own. I have tried different things and it won’t work. I want to end up comparing block 1,1 with every block on the board and then bring back a message. I just want to do it want statement though. If I can’t do it in one how do I repeat it like below and just compare two squares at a time?

[lua]
if (findBlock(1,1) == findBlock(1,2)) then
native.showAlert(“Uh-oh”,“You can’t do that.”,{“Try Again”});

–this stops our alert box from showing
return false
end[/lua]

[import]uid: 72372 topic_id: 12782 reply_id: 312782[/import]

maybe something like this.

[code]
for i = 1, x do – where x = how ever many you want to search
if findBlock(1, 1) == findBlock(1, i) then
native.showAlert(“Uh-oh”,“You can’t do that.”,
{“Try Again”});

–this stops our alert box from showing
return false
end
[/code] [import]uid: 28912 topic_id: 12782 reply_id: 46849[/import]

look at for each, and or do/while

pesudo code

local i = 2;  
  
while ( findBlock(1,1) == findBlock(1,i) ) do   
native.showAlert("Uh-oh","You can't do that.",{"Try Again"});  
i = i + 1  
end  

although i showed you something fast, there is always room for improvements. and this should get you going.

c. [import]uid: 24 topic_id: 12782 reply_id: 46851[/import]

Do you mean something like this?

  
if (findBlock(1,1) == findBlock(1,2) and findBlock(1,1) == findBlock(1,3)) then   
  
--Do stuff here  
  
end  
  

[import]uid: 24111 topic_id: 12782 reply_id: 46852[/import]

Thank you everyone for such a quick response!

HavocHare / Carlos

There would be 9 other spaces I would want to compare block 1,1 to. So in your data how would I represent those specific blocks? I see you have i but that’s what confuses me.

oskwish

I understand the logic the way you did it and that’s what I tried before I posted and it didn’t work. That’s the way I would like to do it though. [import]uid: 72372 topic_id: 12782 reply_id: 46856[/import]