omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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?

    Pythonista
    3
    14
    2836
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RocketBlaster05
      RocketBlaster05 last edited by RocketBlaster05

      Hello! I have a process where I want to make it so that whenever the user presses a button, it adds a value to what I'll call "total," and then saves it. Whenever the app loads next, I want it to be able to link its last saved score with a label in a loaded ui view I have set up already. Can anybody help me out with this?

      Thanks!

      1 Reply Last reply Reply Quote 0
      • RocketBlaster05
        RocketBlaster05 last edited by

        Figured out how to link the text to the label. Still need to know how to make a score keeping system though. Thanks!

        cvp 2 Replies Last reply Reply Quote 0
        • cvp
          cvp @RocketBlaster05 last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • cvp
            cvp @RocketBlaster05 last edited by

            @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()
            
            RocketBlaster05 1 Reply Last reply Reply Quote 0
            • RocketBlaster05
              RocketBlaster05 @cvp last edited by

              @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.

              1 Reply Last reply Reply Quote 0
              • RocketBlaster05
                RocketBlaster05 last edited by

                @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.

                cvp 2 Replies Last reply Reply Quote 0
                • cvp
                  cvp @RocketBlaster05 last edited by

                  @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 🤯

                  RocketBlaster05 1 Reply Last reply Reply Quote 0
                  • RocketBlaster05
                    RocketBlaster05 @cvp last edited by

                    @cvp How to make it so that the player can only do something once every day

                    cvp 1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp @RocketBlaster05 last edited by

                      @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

                      1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @RocketBlaster05 last edited by cvp

                        @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()
                        
                        RocketBlaster05 1 Reply Last reply Reply Quote 0
                        • RocketBlaster05
                          RocketBlaster05 @cvp last edited by

                          @cvp thanks for the reply! I'll try this code out once I get everything situated.

                          cvp 1 Reply Last reply Reply Quote 0
                          • cvp
                            cvp @RocketBlaster05 last edited by

                            @RocketBlaster05 Time to bed, good luck

                            1 Reply Last reply Reply Quote 0
                            • ccc
                              ccc last edited by

                              @cvp said:

                              f.write(str(tot)+'='+str(date.today()))

                              f.write(f"{tot}={date.today()}")  # faster, shorter, easier to read
                              
                              cvp 1 Reply Last reply Reply Quote 0
                              • cvp
                                cvp @ccc last edited by

                                @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 "

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post
                                Powered by NodeBB Forums | Contributors