online multiplayer chess game (note server currently down)
bendn 2022-04-25
parent b466bce · commit d520a30
-rw-r--r--Grid.gd20
-rw-r--r--Piece.gd3
2 files changed, 15 insertions, 8 deletions
diff --git a/Grid.gd b/Grid.gd
index 4a3e976..73c9def 100644
--- a/Grid.gd
+++ b/Grid.gd
@@ -21,7 +21,7 @@ func init_matrix():
for i in range(8):
matrix.append([])
for _j in range(8):
- matrix[i].append(0)
+ matrix[i].append(null)
add_pieces()
@@ -145,10 +145,10 @@ func print_matrix_pretty(mat = matrix):
for i in range(8):
var c = r[i]
var ender = ", " if i < 7 else ""
- if typeof(c) != TYPE_INT:
+ if c:
row += c.realname + ender
else:
- row += "0" + ender
+ row += "null" + ender
print(row + "],")
print("]")
@@ -161,12 +161,18 @@ func _ready():
func square_clicked(position: Vector2):
var spot = matrix[position.y][position.x]
- if typeof(spot) == TYPE_INT:
- if typeof(Globals.last_clicked) == TYPE_INT: # its 0
+ if !spot:
+ print("spot isnt null")
+ if !Globals.last_clicked: # its null
+ print("last clicked is null")
return
+ print("last clicked wasnt null")
Globals.last_clicked.spot(position)
- Globals.last_clicked = 0
- elif typeof(Globals.last_clicked) != typeof(spot) or Globals.last_clicked != spot:
+ Globals.last_clicked = null
+ elif Globals.last_clicked != spot:
+ print("last clicked is different")
+ if Globals.last_clicked:
+ Globals.last_clicked.spot(null)
Globals.last_clicked = spot
spot.clicked()
diff --git a/Piece.gd b/Piece.gd
index ce53070..b132395 100644
--- a/Piece.gd
+++ b/Piece.gd
@@ -16,7 +16,8 @@ func clicked():
func spot(position):
colorrect.hide()
- print("spot ", position)
+ if position:
+ print("spot ", position)
func _ready():
colorrect.rect_size = Globals.piece_size \ No newline at end of file