What am I missin?

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

Hello!

Here’s my lil script to pass from my first scene to the second on a mouse click:

func _ready():
	set_process_input(true)

func _input(event):
	if event is InputEventMouseButton and event_pressed and event.button_index == 1:
		get_tree().change_scene("res://Scenes/chaos.tscn")
		pass

But that just froze the run… Any idea?

:bust_in_silhouette: Reply From: GunPoint

That “pass” should not be there
That’s how your script should look like:

func ready():
	set_process_input(true)
func _input(event):
	if event is InputEventMouseButton and event.pressed and event.button_index == 1:
		get_tree().change_scene("res://Scenes/chaos.tscn")

I tested it, works perfectly

Thxs, but when I click the background of my first scene that doesn’t change anythin. Here is my tree:
Node 2D
Staticbody2D
Collisionshape2D
Sprite
AudioStreamPlayer2D

Where should I put the script? And is it the right order for a full screen image/background and its music? It works fine but for that change of scene.

Syl | 2018-02-25 13:24

since you’re accesing the tree, you can put the script everywhere you want, but in this case you might want to add it to the Node2D. Because of that, its going to change just a line. It would be

extends Node2D
func ready():
    set_process_input(true)
func _input(event):
    if event is InputEventMouseButton and event.pressed and event.button_index == 1:
        get_tree().change_scene("res://Scenes/chaos.tscn")

Make sure the scene path is correct and the scene exitsts and contains the base node “chaos”. You can copy-paste this code and see if it works.
About the background… your sprite is attached to a static body 2d, for a background that’s not necesary… you can add a sprite directly to the base node Node2D. Static bodies are meant to create walls and other static objects in your game.

GunPoint | 2018-02-25 15:46

That works! Cheeers! :slight_smile:

Syl | 2018-02-25 23:16