Page 1 of 1

Is there a way to make a Database?

Posted: Sun Jan 14, 2024 1:21 pm
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.

Re: Is there a way to make a Database?

Posted: Mon Jan 15, 2024 8:54 am
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?

Re: Is there a way to make a Database?

Posted: Mon Apr 08, 2024 9:40 am
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!

Re: Is there a way to make a Database?

Posted: Mon Apr 08, 2024 3:11 pm
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

Re: Is there a way to make a Database?

Posted: Mon Apr 08, 2024 3:13 pm
by Andredron