Syahril
Syahril

Reputation: 1

invalid call to function 'connect' in base 'NAtiveScript'. expected 3 arguments in godot

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

Upvotes: 0

Views: 20

Answers (1)

HumanWrites
HumanWrites

Reputation: 945

The issue is at:

if not db.connect(DB_PATH): print("Failed to open the database at: ", DB_PATH)

I don't think db.connect does what you assume it does. db.connect attempts to register a handler for a signal emitted by the db node. However, db is not a node that emits a signal, it is a reference to the SQLite instance. That SQLite instance does not emit any signals, it simply provides functions to interact with the database.

To open the db file, you need to call db.open_db(), however, the code that you have at the moment is probably not fit for purpose.

I strongly recommend that you start by replicating the minimal example provided by godot-sqlite in their demo application: https://github.com/2shady4u/godot-sqlite/releases/download/v3.0/demo.zip

Upvotes: 0

Related Questions