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

Hello,
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?

print($line.get_point_count())

jgodfrey | 2020-09-08 20:40

Print is indeed giving 3.

Will try and share the screenshot again.

RandomLineGenerated.jpg - Google Drive

Thanks

ashish | 2020-09-09 10:35

Here is the code block:

func _on_btn1_pressed():
print(“btn1”)
if current_button == “none”:
current_button = “btn1”
$btn1.set_texture_pressed(load(“res://GFX/wrong_button.png”))
$btn2.set_texture_pressed(load(“res://GFX/btn_pressed.jpg”))
$ASP.stream = load(“res://SFX/one.wav”)
$ASP.play(0)
else:
$ASP.stream = load(“res://SFX/wrong.wav”)
$ASP.play(0)

func _on_btn2_pressed():
print(“btn2”)
if current_button == “btn1”:
$line.add_point(btn_positions[0])
$line.add_point(btn_positions1)
current_button = “btn2”
$btn2.set_texture_pressed(load(“res://GFX/wrong_button.png”))
$btn3.set_texture_pressed(load(“res://GFX/btn_pressed.jpg”))
$ASP.stream = load(“res://SFX/two.wav”)
$ASP.play(0)

else:
	$ASP.stream = load("res://SFX/wrong.wav")
	$ASP.play(0)

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