Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | purpleGorgon |
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
var board = get_node("/root/Board")
board.mat[0][0] = 4
board._process(1)
print(board.mat[0])
extends Node2D
var mat = [
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
[0,1,0,2,3,4,5,0,1,0,2,3,4,5],
]
func _draw():
for i in range(0, len(mat)):
for j in range(0, len(mat[0])):
var color = "#ff0000"
if mat[i][j] == 1:
color = "#00ff00"
if mat[i][j] == 2:
color = "#00ff00"
if mat[i][j] == 3:
color = "#ddaadd"
if mat[i][j] == 4:
color = "#eeee00"
if mat[i][j] == 5:
color = "#cc00cc"
draw_rect(Rect2(20*j, i*20, 20, 20), color)
func _process(_delta):
update()
I am unable to update my board variable mat to see the color change.
EDIT:
I was creating 2 instances of board it seems. Hiding one of them fixes the issue.