Error in _draw function

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Amanda Dearheart
func ready():
	var Info = []
	
	for Ix in range(1, 10):
		for Iy in range(1, 10):
			Info[Ix][Iy] = randi() % 10
			
	
class DataTable : 

	var x                                      				#    with y,  top Left corner of the grid
	var y 
	var NumColumns                  		  		  		#    width and height of the coltrol defaulted to a size of 10
	var NumRows                      						#    of course, it can be resized
	var Cell = [] 											#    array varible (hopefully string) that contains the info to be displayed
	var Caption  											#    flag that holds the title of the Grid, defulats to 'Unnamed DataGrid
	var Background  										#    flag that holds the texture background of the grid, defaults to nothing

				
	func DrawGrid(Caption = "UnNamed DataGrid", Background = "",  x = 0, y = 0, NumColumns = 10, NumRows = 10):
		
		var Cell_Row 
		var Cell_Column 
		var width 
		var height 
		var font = load('res://fonts/space.tres')
			
		for Row in range(1, NumRows):
			Cell.append([])
			Cell_Row = 1 + (Row * height)
			
			for Col in range(1, NumColumns):
				Cell[Row].append([])
				Cell_Column = 1 + (Col * width)
				
			#   switch to the CanvasLayer node to use the _draw func to actusally draw the grid.

and here is the CanvasLayer node code

extends CanvasLayer


func _draw()->void:
	draw_rect(Rect2(Vector2(x + Cell_Row, y + Cell_Column), Vector2((x + Cell_Row) + width,(y + Cell_Column) + height)), Color.whitesmoke, false, 1, false)
	draw_char(font, Vector2(x + 2, y + 2), Cell[Cell_Row][Cell_Column], "", Color.white)
				
	update()

Edited to fix forum code formatting.

You didn’t say what the error is (or where in the code it’s being reported). Just cut/paste the complete error message.

jgodfrey | 2023-06-01 00:51

I’m sorry for not stating the specifics Mr. jgodfrey…

Simply put, the code is not working as I have written it. I get a blank Panel instead of a grid as I want.

I am using two different nodes to perform the code. The func ready section is in the Panel node, with the following _draw function portion of the code in a node dedicated to the CanvasLayer. As stated. the canvaslayer code is not being called. because I do not know how yet. second, do I even need to put the _draw function in a CanvasLayer node, as the Panel has a section with CanvasItems on it. Thirdly, if the correct path is to combine the code into one node, where do I put the _draw function, or do I put the code now in the Panel function into the CanvasLayer code. Have I confused you yet. Have a blessed day. Eagerly awainting your reply.

Amanda Dearheart | 2023-06-01 05:27

I’m sorry for not stating the specifics Mr. jgodfrey…

Simply put, the code is not working as I have written it. I get a blank Panel instead of a grid as I want.

I am using two different nodes to perform the code. The func ready section is in the Panel node, with the following _draw function portion of the code in a node dedicated to the CanvasLayer. As stated. the canvaslayer code is not being called. because I do not know how yet. second, do I even need to put the _draw function in a CanvasLayer node, as the Panel has a section with CanvasItems on it. Thirdly, if the correct path is to combine the code into one node, where do I put the _draw function, or do I put the code now in the Panel function into the CanvasLayer code. Have I confused you yet. Have a blessed day. Eagerly awaiting your reply.

Amanda Dearheart | 2023-06-01 05:29