For a set of add_point, engine spawning a random line when the first two points are added

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ashish

When add_points as below, an extra random line is created. Not sure why.

$line.add_point(btn_positions[0]) $line.add_point(btn_positions[1])

I have added two points and only one line should be created. However, one random line shoots off from point number one. screenShot of the Issue
Thanks for your help.

Your image isn’t working. Are you sure your line only contains 2 points? What does this return?


jgodfrey | 2020-09-08 20:40

Print is indeed giving 3.

Will try and share the screenshot again.

RandomLineGenerated.jpg - Google Drive


ashish | 2020-09-09 10:35

Here is the code block:

func _on_btn1_pressed():
if current_button == “none”:
current_button = “btn1”
$ = load(“res://SFX/one.wav”)
$ = load(“res://SFX/wrong.wav”)

func _on_btn2_pressed():
if current_button == “btn1”:
current_button = “btn2”
$ = load(“res://SFX/two.wav”)

	$ = load("res://SFX/wrong.wav")

ashish | 2020-09-09 10:48

:bust_in_silhouette: Reply From: jgodfrey

Based on the above, I assume one of the following must be happening:

  • You’re adding additional point(s) to your line elsewhere in the code
  • You’re inadvertently leaving old (previous) points in the line definition
  • You’ve added one or more points to the Line node itself via the inspector. If this is the case, any points you add via code will be in addition to those assigned in the inspector.

If you really only want 2 points, you could call $line.clear_points() before adding the 2 points in your on_btn2_pressed() function.

Thanks a lot. Works.
Best answer.

ashish | 2020-09-10 18:23