0 votes

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.

in Engine by (100 points)

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

print($line.get_point_count())

Print is indeed giving 3.

Will try and share the screenshot again.

https://drive.google.com/file/d/1QuTQYRuLZ4WUaG1n00RXGWIF4Z8MyXeN/view?usp=sharing

Thanks

Here is the code block:

func onbtn1pressed():
print("btn1")
if current
button == "none":
currentbutton = "btn1"
$btn1.set
texturepressed(load("res://GFX/wrongbutton.png"))
$btn2.settexturepressed(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 onbtn2pressed():
print("btn2")
if current
button == "btn1":
$line.addpoint(btnpositions[0])
$line.addpoint(btnpositions[1])
currentbutton = "btn2"
$btn2.set
texturepressed(load("res://GFX/wrongbutton.png"))
$btn3.settexturepressed(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)

1 Answer

0 votes

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.

by (13,160 points)

Thanks a lot. Works.
Best answer.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.