Hi, so I'm making a card game in godot. I want to check for suites and pairs, and basically my code for checking kind of works, but since I'm checking values in a for loop of n+1 and n-1, I need to make sure there's something in the array for n-1 or n+1 and if there's nothing, then do nothing. So I tried with :
number_selected[n+1] != null
but it stops the game, because it's looking for something that doesn't exist in the if function. Is there a function that does that? I tried with back() but no luck since it's the n+1 value I'm looking for. Here's my code :
for n in range (number_selected.size()) :
if number_selected[n+1] != null and n >= 0:
print(number_selected)
if(number_selected[n] == str(int(number_selected[n+1])-int('1'))):
suite_up.append(true)
else:
suite_up.append(false)
if(number_selected[n] == str(int(number_selected[n+1])+int('1'))):
suite_down.append(true)
else:
suite_down.append(false)
if(number_selected[n] == number_selected[n+1]) or (number_selected[n-1] == number_selected[n]):
pair_number.append(number_selected[n])
Thanks!!
(I also tried with
if n+1 < number_selected.size() and n >= 0:
but it skips the last entry...)