Calling groups in between scenes

godot-4

So I’m creating an app that can help me manage what I have to do for each day and I need to call a group that the main scene is attached to as shown in this code. The app is a task list of sorts.
extends Control

@onready var line_edit = $LineEdit

Called when the node enters the scene tree for the first time.

func _ready():
pass

func _on_button_pressed():
print(line_edit.text)
get_tree().call_group(“Information”, “add_information”, line_edit.text)

func _on_button_2_pressed():
get_tree().change_scene_to_file(“res://Scenes/main.tscn”)
The group is called “Information” and I’m sending it a variable that holds a name for a new task so that using it, it can create a new task that pulls up a scene like so.
extends Control

@onready var option_button = $OptionButton

Called when the node enters the scene tree for the first time.

func _ready():
add_to_group(“Information”)
pass # Replace with function body.

func _on_button_pressed():
get_tree().change_scene_to_file(“res://Scenes/TO_DO_List.tscn”)

func add_information(msg : String):
** print(“heya”)**
** option_button.add_item(msg)**

func _on_option_button_item_selected(index):
pass
#if index == 0:
#get_tree().change_scene_to_file(“res://Scenes/Quest_area_1.tscn”)
However the add_information is never called even after I pass the name of the task to it. It doesn’t create a new task with the user inputted variable. The starred areas are with what I need help with.

It seems like the add_information method in your “Information” group isn’t being called. Here are a few things to check:

Group Name Consistency:

Ensure that the group name is exactly the same in both your scripts. Godot is case-sensitive, so “Information” must match perfectly.

Node’s Group Membership:

Confirm that the node is indeed added to the “Information” group. You can debug this by printing the node’s groups:

print(get_groups())

This should include “Information”.

Method Signature:

Make sure the add_information() method is correctly defined to accept a String parameter:

func add_information(msg: String):
    print("heya")
    option_button.add_item(msg)

Calling call_group:

The method should be triggered with:

get_tree().call_group("Information", "add_information", line_edit.text)

Hope this helps :smiley:

I looked through my code, and tried fixing it according to your suggestions and whatever I could gather online however it still refuses to create a new element.

try asking ChatGPT