I had an idea to draw 2D lines with the draw_line() function using the mouse clicks to capture both points for each new line.

Something like this:

My thought was to use an array to store each line as its own separate sub-array with two Vector2s. Here's what I had:

extends Control

var lines: Array

var point: Vector2 = Vector2.ZERO
var new_line = []

func _input(event):
	if event is InputEventMouseButton && event.is_pressed():
		if event.button_index == BUTTON_LEFT:
			point = get_local_mouse_position()
			if new_line.size() < 3:
				new_line.append(point)
			if new_line.size() == 2:
				lines.append(new_line)
				update()
			print(lines)

func _draw():
	for line in lines:
		draw_line(line[0], line[1], Color.white, 0, true)
	new_line.clear()

The problem is that this doesn't work. This will successfully draw a 2d line, but the lines are not persistent. Only one line ever stays on the screen at a time. Not really sure what I'm doing wrong.

It may be simpler to accumulate all positions in PoolVector2Array and use draw_multiline() to draw them all at once:

extends Control

var points: PoolVector2Array

func _process(delta):
	points.set(points.size()-1, get_local_mouse_position())
	update()

func _input(event):
	if event is InputEventMouseButton and event.is_pressed():
		if points.empty():
			points.append(get_local_mouse_position())
		points.append(get_local_mouse_position())

func _draw():
	draw_multiline(points, Color.white)

Thanks! That works perfectly! I knew I was just overthinking it.

a year later