Godot Version
Godot_v4.4.1-stable
Question
this script is getting 2 errors
Line 44:Cannot find member “MODE_SAVE_FILE” in base “FileDialog”.
Line 52:Cannot find member “MODE_OPEN_FILE” in base “FileDialog”.
so this is the script
extends Control
@onready var time_label = $Panel/TimePanel/TimeLabel
@onready var date_label = $Panel/TimePanel/DateLabel
@onready var notes_input = $Panel/NotesPanel/NotesInput
@onready var save_button = $Panel/NotesPanel/SaveButton
@onready var clear_button = $Panel/NotesPanel/ClearButton
@onready var load_button = $Panel/NotesPanel/LoadButton
@onready var num1_input = $Panel/CalculatorPanel/Num1Input
@onready var num2_input = $Panel/CalculatorPanel/Num2Input
@onready var add_button = $Panel/CalculatorPanel/AddButton
@onready var subtract_button = $Panel/CalculatorPanel/SubtractButton
@onready var multiply_button = $Panel/CalculatorPanel/MultiplyButton
@onready var divide_button = $Panel/CalculatorPanel/DivideButton
@onready var result_label = $Panel/CalculatorPanel/ResultLabel
# FileDialog nodes
var save_file_dialog: FileDialog
var load_file_dialog: FileDialog
# Called when the scene is ready
func _ready():
# Connect signals for buttons
save_button.pressed.connect(_on_save_button_pressed)
clear_button.pressed.connect(_on_clear_button_pressed)
load_button.pressed.connect(_on_load_button_pressed)
add_button.pressed.connect(_on_add_button_pressed)
subtract_button.pressed.connect(_on_subtract_button_pressed)
multiply_button.pressed.connect(_on_multiply_button_pressed)
divide_button.pressed.connect(_on_divide_button_pressed)
# Update time and date immediately and then periodically
update_time_and_date()
var timer = Timer.new()
add_child(timer)
timer.timeout.connect(update_time_and_date)
timer.start(60) # Update every 60 seconds (1 minute)
# Create FileDialog for saving
save_file_dialog = FileDialog.new()
save_file_dialog.name = "save_file" # Set the name of the node
save_file_dialog.mode = FileDialog.MODE_SAVE_FILE # <--- Use this mode for saving
save_file_dialog.filters = PackedStringArray(["*.txt ; Text Files"])
save_file_dialog.file_selected.connect(_on_save_dialog_file_selected)
add_child(save_file_dialog)
# Create FileDialog for loading
load_file_dialog = FileDialog.new()
load_file_dialog.name = "load_file" # Set the name of the node
load_file_dialog.mode = FileDialog.MODE_OPEN_FILE # <--- Use this mode for opening
load_file_dialog.filters = PackedStringArray(["*.txt ; Text Files"])
load_file_dialog.file_selected.connect(_on_load_dialog_file_selected)
add_child(load_file_dialog)
# Function to update time and date
func update_time_and_date():
var now = Time.get_datetime_dict_from_system()
var time_str = str(now.hour).pad_zeros(2) + ":" + str(now.minute).pad_zeros(2)
time_label.text = "Time: " + time_str
var date_str = str(now.day).pad_zeros(2) + "/" + str(now.month).pad_zeros(2) + "/" + str(now.year)
date_label.text = "Date: " + date_str
# Notes functionality
var current_notes_path = ""
func _on_save_button_pressed():
save_file_dialog.popup_centered()
func _on_save_dialog_file_selected(path: String):
current_notes_path = path
var file = FileAccess.open(path, FileAccess.WRITE)
if file:
file.store_line(notes_input.text)
file.close()
print("Notes saved to: ", path)
else:
printerr("Error: Could not open file for saving notes.")
func _on_clear_button_pressed():
notes_input.clear()
current_notes_path = ""
print("Notes cleared!")
func _on_load_button_pressed():
load_file_dialog.popup_centered()
func _on_load_dialog_file_selected(path: String):
current_notes_path = path
var file = FileAccess.open(path, FileAccess.READ)
if file:
if not file.eof_reached():
notes_input.text = file.get_line()
file.close()
print("Notes loaded from: ", path)
else:
print("Error: Could not open file for loading notes.")
notes_input.clear()
# Calculator functionality
func _on_add_button_pressed():
_perform_operation(func(a, b): return a + b)
func _on_subtract_button_pressed():
_perform_operation(func(a, b): return a - b)
func _on_multiply_button_pressed():
_perform_operation(func(a, b): return a * b)
func _on_divide_button_pressed():
_perform_operation(func(a, b):
if b != 0:
return a / b
else:
result_label.text = "Error: Division by Zero"
return null
)
func _perform_operation(operation: Callable):
var num1 = 0.0
var num2 = 0.0
# Validate the input before performing the operation
if num1_input.text.is_valid_float() and num2_input.text.is_valid_float():
num1 = float(num1_input.text)
num2 = float(num2_input.text)
else:
result_label.text = "Invalid input"
return
var result = operation.call(num1, num2)
if result != null:
result_label.text = "Result: " + str(result)