Question:
I’m having trouble with replit db. after I run the code and the database saves something. I rerun the program and boom. The database is reset. I have checked for all reset()
functions. They are not in the code but they are defined. Please ignore the probabilities and the probability. They are not important in the code and is only used in 1 section of that code which does not even affect anything.
Repl link:
https://replit.com/@Idkwhttph/Mining-Simulator?v=1
from termcolor import colored
from colorama import Fore as F
from colorama import Style as S
from getkey import getkey,keys
from replit import clear,db
from probabilities import probability
import os
import sys
from time import sleep
import shutil
from os import environ
import random
from random import randint as rand
try:
print(db['Test.keys']);clear()
except:
db['Text.keys'] = 7777
db['Miners'] = 0
db['Mining_speed'] = 5
db['Sapphire'] = 0
db['Ruby'] = 0
db['emerald'] = 0
db['diamond'] = 0
db['topaz'] = 0
db['aquamarine'] = 0
db['amethyst'] = 0
db['Mining_yield'] = 2
db['multiplier'] = 0
db['rebirths'] = 0
db['Money'] = 0
db['sell_Sapphire'] = 2.4
db['sell_Ruby'] = 3.6
db['sell_emerald'] = 4.4
db['sell_diamond'] = 6.1
db['sell_topaz'] = 7
db['sell_aquamarine'] = 9.2
db['sell_amethyst'] = 12.4
text_keys =''
miners =''
mining_speed = ''
sapphire = ''
ruby =''
emerald =''
diamond =''
topaz = ''
aquamarine = ''
amethyst = ''
mining_yield = ''
multiplier = ''
rebirths = ''
money = ''
def reset():
db['Text.keys'] = 7777
db['Miners'] = 0
db['Mining_speed'] = 5
db['Sapphire'] = 0
db['Ruby'] = 0
db['emerald'] = 0
db['diamond'] = 0
db['topaz'] = 0
db['aquamarine'] = 0
db['amethyst'] = 0
db['Mining_yield'] = 2
db['multiplier'] = 0
db['rebirths'] = 0
db['Money'] = 0
db['sell_Sapphire'] = 2.4
db['sell_Ruby'] = 3.6
db['sell_emerald'] = 4.4
db['sell_diamond'] = 6.1
db['sell_topaz'] = 7
db['sell_aquamarine'] = 9.2
db['sell_amethyst'] = 12.4
del db['37364824672838']
text_keys =''
miners =''
mining_speed = ''
sapphire = ''
ruby =''
emerald =''
diamond =''
topaz = ''
aquamarine = ''
amethyst = ''
mining_yield = ''
multiplier = ''
rebirths = ''
money = ''
def unpack_data():
global text_keys,miners,mining_speed,sapphire,ruby,emerald,diamond,topaz,aquamarine,amethyst,mining_yield,multiplier,rebirths,money,sell_sapphire,sell_ruby,sell_emerald,sell_diamond,sell_topaz,sell_aquamarine,sell_amethyst,probability
text_keys = db['Text.keys']
miners = db['Miners']
mining_speed =db['Mining_speed']
sapphire = db['Sapphire']
ruby = db['Ruby']
emerald =db['emerald']
diamond =db['diamond']
topaz = db['topaz']
aquamarine = db['aquamarine']
amethyst = db['amethyst']
mining_yield = db['Mining_yield']
multiplier = db['multiplier']
rebirths = db['rebirths']
money =db['Money']
def enter_to_continue():
print(f'{S.BRIGHT}|{F.BLUE}Enter{F.WHITE}|To Continue{S.RESET_ALL}')
input()
bright = S.BRIGHT
normal = S.NORMAL
reset = S.RESET_ALL
blue = F.BLUE
white = F.WHITE
purple = F.MAGENTA
green = F.GREEN
dim = S.DIM
red = F.RED
unpack_data()
def getinput(menu):
while True:
global opt,breaks,bright,normal,reset,blue,white,purple,green,dim,debug,text_keys,miners,mining_speed,sapphire,ruby,emerald,diamond,topaz,aquamarine,amethyst,mining_yield,multiplier,rebirths,money,sell_sapphire,sell_ruby,sell_emerald,sell_diamond,sell_topaz,sell_aquamarine,sell_amethyst,probability,money,money_2
money_2 = db['Money']
bright = S.BRIGHT
normal = S.NORMAL
reset = S.RESET_ALL
blue = F.BLUE
white = F.WHITE
purple = F.MAGENTA
green = F.GREEN
dim = S.DIM
Mining1 = 0
opt = ''
selected = 0
solution_get_input = 0
key = ""
breaks = False
if breaks == True:
break
solution_get_input = 0
selected = 0
key = ""
while True:
try:
printInMiddle('Mining_Simulator.exe')
printInMiddle('------------------------------------------------------------')
printInMiddle(f'You have $ {db["Money"]}')
for i, item in enumerate(menu):
if i == selected:
print(colored(f"{bright}-> {bright}[{F.GREEN}{i if debug else i+1}{S.RESET_ALL}] {menu[i]}{normal}"))
else:
print(f" {bright}[{F.YELLOW}{i if debug else i+1}{S.RESET_ALL}] {menu[i]}{normal}")
key = getkey()
if key.isdigit():
clear()
solution_get_input = int(key)
break
elif key == keys.UP:
clear()
selected = (selected - 1) % len(menu)
if selected == -1:
selected = (selected + len(menu)+1) % len(menu)
elif key == keys.DOWN:
clear()
selected = (selected + 1) % len(menu)
if selected > len(menu):
selected = (selected - len(menu)-1) % len(menu)
elif key == "\n":
solution_get_input = selected
opt = menu[solution_get_input]
clear()
else:
clear()
clear()
if opt == 'Mine':
clear()
print(f'{bright}{purple}Mining...{white}{normal}')
sleep(1.2*db['Mining_speed'])
for i in range(db['Miners']+1):
sleep(0.2)
Mining_1 = rand(1,db['Mining_yield'])
ore = random.choice(probability)
if i == 0:
print(f'{bright}You Mined {blue}{Mining_1}{white} {purple}{ore}{white}')
if ore == 'Sapphire':
sapphire+=Mining_1
elif ore == 'Ruby':
ruby+=Mining_1
elif ore == 'emerald':
emerald+=Mining_1
elif ore == 'topaz':
topaz+=Mining_1
elif ore == 'diamond':
diamond+=Mining_1
elif ore == 'aquamarine':
aquamarine+=Mining_1
elif ore == 'amethyst':
amethyst+=Mining_1
if i == 0:
pass
else:
print(f'{bright}Your Miners Mined {blue}{Mining_1}{white} {purple}{ore}{white}')
if ore == 'Sapphire':
sapphire+=Mining_1
elif ore == 'Ruby':
ruby+=Mining_1
elif ore == 'emerald':
emerald+=Mining_1
elif ore == 'topaz':
topaz+=Mining_1
elif ore == 'diamond':
diamond+=Mining_1
elif ore == 'aquamarine':
aquamarine+=Mining_1
elif ore == 'amethyst':
amethyst+=Mining_1
# db['sell_Sapphire'] = 2.4
#db['sell_Ruby'] = 3.6
#db['sell_emerald'] = 4.4
#db['sell_diamond'] = 6.1
#db['sell_topaz'] = 7
#db['sell_aquamarine'] = 9.2
#db['sell_amethyst'] = 12.4
enter_to_continue()
clear()
save()
break
elif opt == 'Hewwo':
print('Yeah whatever. Hello!')
enter_to_continue()
breaks = True
clear()
break
elif opt == 'xxxx':
print('No you are just imagining that ur a cat lolz')
enter_to_continue()
breaks = True
clear()
break
elif opt == 'Sell Ores':
print(f'{bright}You sold')
sleep(0.5)
print(f"{db['Sapphire']} Sapphires");sleep(0.5)
print(f"{db['Ruby']} Ruby");sleep(0.5)
print(f"{db['emerald'] } Emerald");sleep(0.5)
print(f"{db['diamond'] } Diamond");sleep(0.5)
print(f"{db['topaz']} Topaz");sleep(0.5)
print(f"{db['aquamarine']} Aquamarine");sleep(0.5)
print(f"{db['amethyst']} Amethyst");sleep(0.5)
money_2 = money
#db['sell_Sapphire'] = 2.4
#db['sell_Ruby'] = 3.6
#db['sell_emerald'] = 4.4
#db['sell_diamond'] = 6.1
#db['sell_topaz'] = 7
#db['sell_aquamarine'] = 9.2
#db['sell_amethyst'] = 12.4
money+=db['Ruby'] *db['sell_Ruby']
money+=db['Sapphire'] * db['sell_Sapphire']
money+=db['emerald'] *db['sell_emerald']
money+=db['diamond'] *db['sell_diamond']
money+=db['topaz'] *db['sell_topaz']
money+=db['aquamarine'] * db['sell_aquamarine']
money+=db['amethyst'] *db['sell_amethyst']
print(f'For ${green}{money-money_2}{white}{normal}')
db['Ruby'] =0
db['Sapphire']=0
db['emerald'] =0
db['diamond'] =0
db['topaz'] =0
db['aquamarine'] =0
db['amethyst'] =0
enter_to_continue()
clear()
save()
break
#add more elif statements as you go!
except Exception as e:
print("An exception occurred.")
# Save state here.
raise e
def write(string: str, speed: int=.05) -> None:
for char in string:
sys.stdout.write(char)
sys.stdout.flush()
sleep(speed)
def printInMiddle(text, columns=shutil.get_terminal_size().columns):
# Get the current width of the console
console_width = columns
# Calculate the padding for the left side
padding = (console_width - len(text)) // 2 + 5
# Print the padded text
print(' ' * padding + text)
debug = False
authors = [
"Idkwhttph",
]
##### ALL DEBUG FEATURES MUST CHECK debug == True #####
# this is to disable people from directly accessing dev tools.
debug = environ["REPL_OWNER"] in authors and False # If you want to test end user UI
def save():
global text_keys,miners,mining_speed,sapphire,ruby,emerald,diamond,topaz,aquamarine,amethyst,mining_yield,multiplier,rebirths,money,sell_sapphire,sell_ruby,sell_emerald,sell_diamond,sell_topaz,sell_aquamarine,sell_amethyst,probability
db['Text.keys'] = text_keys
db['Miners'] = miners
db['Mining_speed'] = mining_speed
db['Sapphire'] = sapphire
db['Ruby'] = ruby
db['emerald'] = emerald
db['diamond'] = diamond
db['topaz'] = topaz
db['aquamarine'] = aquamarine
db['amethyst'] = amethyst
db['Mining_yield'] = mining_yield
db['multiplier'] = multiplier
db['rebirths'] = rebirths
db['Money'] = money
db['sell_Sapphire'] = 2.4
db['sell_Ruby'] = 3.6
db['sell_emerald'] = 4.4
db['sell_diamond'] = 6.1
db['sell_topaz'] = 7
db['sell_aquamarine'] = 9.2
db['sell_amethyst'] = 12.4
try:
print(db['37364824672838']);clear()
except:
db['37364824672838'] = 32236326
text_keys = 0.23232323
save()
write(f'{bright}Welcome to to Mining Simulator, where you can {blue}mine{white} precious {green}gemstones{white} and sell them for {green}money{white}, then you can Buy {purple}miners{white} to mine for you When you buy a miner, It can exponentially ( my english is trash pls correct if im wrong lolz ) increase your Mining yield and your profits! Thank you for your time, hope you enjoy!')
print('\n')
enter_to_continue()
clear()
sleep(2)
if debug:
menu = [
'Mine',
'Buy Upgrades',
'Buy Miners',
'Buy Rebirth Upgrades',
'Rebirth options' ,
'Sell Ores'
'Devtool Console'
]
else:
menu = [
'Mine',
'Buy Upgrades',
'Buy Miners',
'Buy Rebirth Upgrades',
'Rebirth options' ,
'Sell Ores'
]
unpack_data()
while True:
try:
while True:
getinput(menu)
except Exception as e:
save()
raise e
currently, mine and sell works, I will add the others later.