sqlite - invalid call to function 'connect' in base 'NAtiveScript'. expected 3 arguments in godo

时间: 2025-01-06 admin 业界

im using godot SQLite for my project there is to many invalid. here is my code

and im using godot 3.6 `extends Node

Reference the SQLite plugin script

#onready var db = preload("res://addons/sqlite/godot-sqlite.gd").new() const db = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")

Path to your SQLite database

const DB_PATH = "res://random_words.db"

var words = [] # List of words loaded from the database var special_characters = [".", "!", "?"]

func _ready(): load_words_from_database()

Function to load words from the SQLite database

Function to load words from the SQLite database

func load_words_from_database(): # Open the database if not db.connect(DB_PATH): print("Failed to open the database at: ", DB_PATH) return

# Execute the query
var query = "SELECT word FROM words;"
if not db.query(query):
    print("Failed to execute query: ", query)
    db.close()
    return

# Fetch rows and populate the words array
words.clear()
while db.next_row():
    words.append(db.get_column_text(0))  # First column is 'word'

print("Loaded words: ", words.size())
db.close()

Function to generate a random prompt

func get_prompt() -> String: if words.empty(): return "No words available in the database!"

var word_index = randi() % words.size()
var special_index = randi() % special_characters.size()

var word = words[word_index]
var special_character = special_characters[special_index]

var formatted_word = word.substr(0, 1).to_upper() + word.substr(1).to_lower()

return formatted_word + special_character

i have you guys can help for future study. thank you