Is there a way to make a Database?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
tsuntere
Newbie
Posts: 3
Joined: Sat Jan 13, 2024 10:33 pm
Contact:

Is there a way to make a Database?

#1 Post by tsuntere »

I'm kinda new to programming and I love using Renpy so I was looking forward to make my final assignment with it. But I need to make 3 databases in the game and I'm not sure if it is possible with Python or exporting the apk in Android Studio.

I can't find anything in the documentation so I'm here for help.

Thanks in advance.

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Is there a way to make a Database?

#2 Post by m_from_space »

tsuntere wrote: Sun Jan 14, 2024 1:21 pmBut I need to make 3 databases in the game...
I mean a simple class can be a database. I am not sure how complex your database structure has to be. What I can tell you is, that Renpy sadly does not ship with sqlite3 (which is part of the Python standard library). But you can actually create a subprocess that invokes another python binary, that will then import sqlite3. I don't recommend doing this being new to programming though. Maybe there are other python database packages out there, that you can simply install into the game's "python-packages" folder and then import.

But again, what are you actually hoping to store inside those databases?

tsuntere
Newbie
Posts: 3
Joined: Sat Jan 13, 2024 10:33 pm
Contact:

Re: Is there a way to make a Database?

#3 Post by tsuntere »

m_from_space wrote: Mon Jan 15, 2024 8:54 am
tsuntere wrote: Sun Jan 14, 2024 1:21 pmBut I need to make 3 databases in the game...
I mean a simple class can be a database. I am not sure how complex your database structure has to be. What I can tell you is, that Renpy sadly does not ship with sqlite3 (which is part of the Python standard library). But you can actually create a subprocess that invokes another python binary, that will then import sqlite3. I don't recommend doing this being new to programming though. Maybe there are other python database packages out there, that you can simply install into the game's "python-packages" folder and then import.

But again, what are you actually hoping to store inside those databases?
I needed because this game is my final project in my school and it's obligatory. But I already solved, thanks!

User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: Is there a way to make a Database?

#4 Post by Andredron »

Only the old renpy python version used to make a base like this.

Download and install python 2.7.10 (https://www.python.org/downloads/release/python-2710/)
Copy:
C:\Program Files (x86)\Python\Python 2.7.10\Lib\sqlite3
C:\Program Files (x86)\Python\Python 2.7.10\DLLs\_sqlite3.pyd
C:\Program Files (x86)\Python\Python 2.7.10\DLLs\sqlite3.dll.
In the folder:
C:\Program Files (x86)\RenPy\renpy-*.**.**.*-sdk\lib\windows-i686\Lib

To check, add the following code to the beginning of script.py:
init:
python:
import sqlite3
conn = sqlite3.connect(config.basedir+'/example.db')
cur = conn.cursor()
cur.execute("insert into npc values ('snake', 'python')")
cur.execute("select npc_type, npc_name from npc where id='snake'")
result = cur.fetchone()

Example of working with Sqlite3:
cur.execute("select * from airlines limit 5;")
results = cur.fetchall()
print results

BerkeleyDB can be added in the same simple way:
Copy:
C:\Program Files (x86)\Python\Python 2.7.10\Lib\bsddb
C:\Program Files (x86)\Python\Python 2.7.10\DLLs\_bsddb.pyd.
In the folder:
C:\Program Files (x86)\RenPy\renpy-*.**.**.*-sdk\lib\windows-i686\Lib

To check, add the following code to the beginning of script.py:
init:
python:
import bsddb
db = bsddb.btopen(config.basedir+'/spam.db')


Example of working with BerkeleyDB:
db['player'] = '123'
print db


Post Reply

Who is online

Users browsing this forum: No registered users