Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Python by ddffffgghhh ( 1 year ago )
extends Node2D
var db = null
func _ready():
$popup.visible = false
var SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
db = SQLite.new()
db.path = "meubanco.db"
db.open_db()
var query = "CREATE TABLE IF NOT EXISTS jogador (id INTEGER PRIMARY KEY AUTOINCREMENT, nome TEXT, pontos INTEGER);"
db.query(query)
func salvar_jogador():
var id = $TextEditId.text
var nome = $TextEditNome.text
var pontos = $TextEditPontos.text
if (id==""):
inserir_jogador(nome, pontos)
else:
alterar_jogador(id, nome, pontos)
func alterar_jogador(id, nome, pontos):
db.query("UPDATE jogador SET nome='" + nome + "', pontos=" + pontos + " WHERE id = " + id + ";")
$popup/msg.text = "Alterado com sucesso!"
$popup.visible = true
func inserir_jogador(nome, pontos):
db.query("INSERT INTO jogador (nome, pontos) values ('" + nome + "'," + pontos + ");")
$popup/msg.text = "Inserido com sucesso!"
$popup.visible = true
func excluir_jogador():
var id = $TextEditId.text
db.query("DELETE FROM jogador WHERE id = " + id + ";")
$popup/msg.text = "Excluído com sucesso!"
$popup.visible = true
func buscar_jogadores():
db.query("SELECT * FROM jogador;")
var tabela = db.query_result
$TextEditListaRanking.text = ""
for linha in tabela:
$TextEditListaRanking.text += str(linha["id"]) + " - " + str(linha["nome"]) + " - " + str(linha["pontos"]) + "\n"
func fechar_popup():
$popup.visible = false
func limpar_campos():
$TextEditId.text = ""
$TextEditNome.text = ""
$TextEditPontos.text = ""
$TextEditListaRanking.text = ""
Revise this Paste