#Scripting help (please)

4 messages · Page 1 of 1 (latest)

hidden hull
#

I have this script that at this point, Im just trying to make work. I have been looking over tutorials and documents but its hard to take it all in at once. This is my script ```extends Area2D

Reference to your AudioStreamPlayer2D node

@onready var portal_sound: AudioStreamPlayer2D = $PortalSound

Reference to your Sprite node for the fade effect

@onready var fade_sprite: Sprite2D = $fade # Adjust the name to match your actual node name

func _ready():
# Connect the "area_entered" signal to the "_on_area_entered" function
area_entered.connect(area_entered, "_on_area_entered")

func _on_area_entered(area: Area2D) -> void:
# Check if the area is your character
if area.name == "Player":
# Play the portal sound
portal_sound.play()

    # Configure the fade effect
    fade_sprite.custom_minimum_size = get_viewport().size  # Make it cover the entire screen
    fade_sprite.custom_minimum_size.x *= 2  # Ensure it covers both horizontal sides
    fade_sprite.custom_minimum_size.y *= 2  # Ensure it covers both vertical sides
    fade_sprite.custom_minimum_size = fade_sprite.custom_minimum_size.ceil()  # Round up to the nearest integer
    fade_sprite.modulate = Color(0, 0, 0, 0)  # Start with fully transparent

    # Create a Tween for the fade effect
    var tween = get_tree().create_tween()
    add_child(tween)

    # Tween the transparency to 1 (fully opaque)
    tween.interpolate_property(fade_sprite, "modulate:a", 0, 1, 1.0, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)

    # Start the tween
    tween.start()

    # Wait for the sound to finish
    await portal_sound.finished

    # Transition to the main menu scene
    get_tree().change_scene("res://main_menu.tscn")
#

The problem is I keep getting these same errors on line 11 and I dont know what exactly Im doing wrong or how to fix it - Line 11:Invalid argument for "connect()" function: argument 1 should be "Callable" but is "Signal".
Line 11:Cannot pass a value of type "String" as "int".
Line 11:Invalid argument for "connect()" function: argument 2 should be "int" but is "String".

mossy pecan
#

Is this in 4.x?

#

You are passing in the signal as an argument to a method that you are calling on that same signal. connect() only takes the callable you want to connect to it. In this case your method name without quotation marks.