The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hi, i'm a complete beginner to godot so sorry if my code is unreadable trash. Here it is:


extends Sprite
export (PackedScene) var Pipe
onready var new_pipe = Pipe.instance()

func spawnpipe():
new
pipe.position = Vector2(-30.941, 4.235)
addchild(newpipe)
print("Duplicated")


I'm sorry i cant get the code sample thing to work ):

For context, i'm making a flappy bird clone and i need the pipes that you go over to spawn and spawn and spawn. The spawn pipe function is hooked up to a timer and it gives the error above.

in Engine by (12 points)

1 Answer

–1 vote

The error is telling you that the variable Pipe has no value ("Nil"). This is because you've written code to have it assigned in the Inspector, but it seems you haven't assigned it a value. Go to the inspector and drop the scene file in there.

Also, the way you've written it, you're only making one instance ever for the whole game. This line:

var new_pipe = Pipe.instance()

should appear in your spawn() function if you want to be able to make a new pipe every time you call it.

by (22,191 points)
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 [email protected] with your username.