Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Keep track of Progress every time the app loads?
-
@RocketBlaster05 you could save your score in a file, either at each increase, either at close of program. The program would also need to read the file at its begin.
-
@RocketBlaster05 try
import ui import os v = ui.View() v.background_color = 'white' fil = 'total.txt' if os.path.exists(fil): with open(fil,mode='rt') as f: tot = int(f.read()) else: tot = 0 b = ui.ButtonItem() b.title = 'increase' def increase(sender): global tot tot += 1 v.name = str(tot) with open(fil,mode='wt') as f: f.write(str(tot)) b.action = increase v.right_button_items = (b,) v.name = str(tot) v.present()
-
@cvp Once again thanks for solving yet another of my questions lol. Hopefully this is the last big leap I need to overcome for this app.
-
@cvp ah nope nevermind I'm probably gonna end up asking something later but I'm not there yet lol. Its going to revolve around setting daily limits to things if you know anything about that.
-
@RocketBlaster05 said:
Its going to revolve around setting daily limits to things if you know anything about that.
English is far to be my mother language, sorry, I don't understand your sentence 🤯
-
@cvp How to make it so that the player can only do something once every day
-
@RocketBlaster05 you could store in the file, the today date and the total and only enable the button if the stored date is not today
-
@RocketBlaster05 very quick and dirty. Before running it the first time, remove your current total.txt file
import ui import os from datetime import date v = ui.View() v.background_color = 'white' fil = 'total.txt' if os.path.exists(fil): with open(fil,mode='rt') as f: r = f.read() t,d = r.split('=') tot = int(t) else: tot = 0 b = ui.ButtonItem() b.title = 'increase' def increase(sender): global tot tot += 1 v.name = str(tot) with open(fil,mode='wt') as f: f.write(str(tot)+'='+str(date.today())) b.action = increase if d == str(date.today()): b.enabled = False v.right_button_items = (b,) v.name = str(tot) v.present()
-
@cvp thanks for the reply! I'll try this code out once I get everything situated.
-
@RocketBlaster05 Time to bed, good luck
-
@cvp said:
f.write(str(tot)+'='+str(date.today()))
f.write(f"{tot}={date.today()}") # faster, shorter, easier to read
-
@ccc I had hesitated because, if I know how to do for the file writing, I don't know how for the file reading in the same kind of way.
PS It is also why I wrote "dirty "