Android Question Wordsearch Puzzle

brianwiz12

Active Member
Licensed User
Longtime User
Im getting a syntax error and invalid number of indices.2 expected in the following code

[CODE lang="b4x" title="indices.2 expected. Invalid Number" highlight="2-4"]Sub CheckHorizontal(row As Int, col As Int, checkLength As Int, word As String) As Boolean
If col + checkLength > wordSearchGrid(row).Length Then
Return False ' Word goes out of bounds horizontally
End If

For i = 0 To checkLength - 1
If wordSearchGrid(row, col + i) <> word.CharAt(i) Then
Return False ' Mismatch found, word not present horizontally
End If
Next
Return True ' Word found horizontally
End Sub[/CODE]
 
Is wordSearchGrid() a 1-dimensional array, or 2-dimensional?

If it is an array of arrays, then it is new to me that you could access it using two indices inside one set of brackets.
 
Upvote 0
Lol you could put the letter check inside a Try so that if you access wordSearchGrid() past its edges then it does a Catch Return False.

Should work, but feels dangerous.
 
Upvote 0
[CODE lang="b4x" title="The Year of Programming Dangerously" highlight="3,7,8,9"]Sub CheckHorizontal(row As Int, col As Int, checkLength As Int, word As String) As Boolean
For i = 0 To checkLength - 1
Try
If wordSearchGrid(row, col + i) <> word.CharAt(i) Then
Return False ' Mismatch found, word not present horizontally
End If
Catch
Return False ' Word goes out of bounds
End Try
Next
Return True ' Word found horizontally
End Sub[/CODE]
 
Upvote 0
Back
Top