omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. timjhinton

    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.


    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 11
    • Best 0
    • Controversial 0
    • Groups 0

    timjhinton

    @timjhinton

    1
    Reputation
    612
    Profile views
    11
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    timjhinton Unfollow Follow

    Latest posts made by timjhinton

    • RE: Label not updating

      @cvp Hmm I’m not exactly sure how to explain it differently. Simply put, I am creating a label and setting the value to a variable. When I update the value of that variable, the label is not updating. If I close out the program and open it back up then it displays the new, correct value.

      I wonder if the issue is happening because I have it presenting a sub menu scene where the button is that calls the function that updates values and then I dismiss that scene. This is when I expect the label value to update.

      Anyways, I’d be happy to send you the code via email or something for you to take a look?

      posted in Pythonista
      timjhinton
      timjhinton
    • RE: Label not updating

      @cvp Well, that didn’t work how I hoped. So for the update_labels() and the other function that didn’t get quoted right there is really no indention. All of the code inside of the function definition is at the same indention.

      def update_labels(self):
      		self.maddex_accounts, self.ryker_accounts = BudgetClasses.TransMethod.get_budget_values()
      		self.Maddex_spending_amount.text = str(self.maddex_accounts[7])
      		self.Maddex_savings_amount.text = str(self.maddex_accounts[8])
      		self.Maddex_tithing_amount.text = str(self.maddex_accounts[9])
      		self.Ryker_spending_amount.text = str(self.ryker_accounts[7])
      		self.Ryker_savings_amount.text = str(self.ryker_accounts[8])
      		self.Ryker_tithing_amount.text = str(self.ryker_accounts[9]) 
      

      Like so. I think that clears it all up?

      posted in Pythonista
      timjhinton
      timjhinton
    • RE: Label not updating

      @cvp Ahh gotcha. I can do that. Here they are:

      mad_spend_label = str(self.maddex_accounts[7])
      		self.Maddex_spending_amount = LabelNode(mad_spend_label, font=menu_button_font, color='black', position=(-(self.menu_bg.size.w/3), self.menu_bg.size.h/2 - 160), parent=self.menu_bg)
      		self.account_values.append(self.Maddex_spending_amount)
      
      def run_weekly(self):
      		self.paused = True
      		self.run_weekly_scene = BudgetClasses.WeeklySubMenuScene("Weekly Payout", "Who gets paid?",["Both", "Maddex", "Ryker", "Back"])
      		self.present_modal_scene(self.run_weekly_scene)
      		self.run_weekly_scene = None
      		self.update_labels()
      
      def weekly_both(self):
      		#[0 kid, 1 ID, 2 date, 3 desc, 4 begin_spend, 5 begin_save, 6 begin_tithe, 7 end_spend, 8 end_save, 9 end_tithe]
      		maddex_accounts, ryker_accounts = TransMethod.get_budget_values()
      		new_mad_accounts = self.apply_weekly(maddex_accounts)
      		new_ryk_accounts = self.apply_weekly(ryker_accounts)
      		TransMethod.send_mad_trans(new_mad_accounts)
      		TransMethod.send_ryker_trans(new_ryk_accounts)
      		self.dismiss_modal_scene()
      		self.paused = False
      

      I even tried to manually update it with this function:

      def update_labels(self):
      		self.maddex_accounts, self.ryker_accounts = BudgetClasses.TransMethod.get_budget_values()
      		self.Maddex_spending_amount.text = str(self.maddex_accounts[7])
      		self.Maddex_savings_amount.text = str(self.maddex_accounts[8])
      		self.Maddex_tithing_amount.text = str(self.maddex_accounts[9])
      		self.Ryker_spending_amount.text = str(self.ryker_accounts[7])
      		self.Ryker_savings_amount.text = str(self.ryker_accounts[8])
      		self.Ryker_tithing_amount.text = str(self.ryker_accounts[9])
      

      Does that help?

      posted in Pythonista
      timjhinton
      timjhinton
    • Label not updating

      Hello, I need a little help here. I can’t figure out why my label isn’t updating. Essentially, I create a label that has a number value. That works fine. But, with a button push I bring up a modal scene and press another button. This option then dismisses the modal scene, the value that is displayed in the LabelNode is updating in value because it is written to another file, but the value that is being displayed isn’t updating to the new value. I’ll try to copy and paste the functions that I think are the most important.

      First, here is the LabelNode created in the setup() for the Scene:

      mad_spend_label = str(self.maddex_accounts[7])
      		self.Maddex_spending_amount = LabelNode(mad_spend_label, font=menu_button_font, color='black', position=(-(self.menu_bg.size.w/3), self.menu_bg.size.h/2 - 160), parent=self.menu_bg)
      

      This is the function that is called when said button is pushed:

      def run_weekly(self):
      		self.paused = True
      		self.run_weekly_scene = BudgetClasses.WeeklySubMenuScene("Weekly Payout", "Who gets paid?",["Both", "Maddex", "Ryker", "Back"])
      		self.present_modal_scene(self.run_weekly_scene)
      		self.run_weekly_scene = None
      		self.update_labels()
      

      Here is a function I created trying to get it to display the correct value:

      def update_labels(self):
      		self.maddex_accounts, self.ryker_accounts = BudgetClasses.TransMethod.get_budget_values()
      		self.Maddex_spending_amount.text = str(self.maddex_accounts[7])
      		self.Maddex_savings_amount.text = str(self.maddex_accounts[8])
      		self.Maddex_tithing_amount.text = str(self.maddex_accounts[9])
      		self.Ryker_spending_amount.text = str(self.ryker_accounts[7])
      		self.Ryker_savings_amount.text = str(self.ryker_accounts[8])
      		self.Ryker_tithing_amount.text = str(self.ryker_accounts[9])
      

      Here is the function that is called from the WeeklySubMenuScene that is presented:

      def weekly_both(self):
      		#[0 kid, 1 ID, 2 date, 3 desc, 4 begin_spend, 5 begin_save, 6 begin_tithe, 7 end_spend, 8 end_save, 9 end_tithe]
      		maddex_accounts, ryker_accounts = TransMethod.get_budget_values()
      		new_mad_accounts = self.apply_weekly(maddex_accounts)
      		new_ryk_accounts = self.apply_weekly(ryker_accounts)
      		TransMethod.send_mad_trans(new_mad_accounts)
      		TransMethod.send_ryker_trans(new_ryk_accounts)
      		self.dismiss_modal_scene()
      		self.paused = False
      

      So, when that function is run it is successful because the updated values are written to a separate file, but that updated value wont display. If I close the program and then start it again then it displays the updated value that is retrieved from the separate file. I’d like for the value of that LabelNode to update! Any help would be appreciated.

      posted in Pythonista
      timjhinton
      timjhinton
    • Text box for user input using Scene

      Hello there,
      I’m using the scene module for my project and I am trying to have a small screen pop up with a box for text input. With the UI script it is easy to add a editable text box and drop it on the screen. Can I do the same thing using scene? I went through the documentation hoping that a Labelnode could be set to be editable.
      Any suggestions on how to do this?

      posted in Pythonista
      timjhinton
      timjhinton
    • RE: Collisions

      @JonB said:

      I haven't tried you code yet, but I have recently been helping my son debug a similar issue on a javascript game he is trying to write.

      What I suggested was to have a debugging mode, where you display a label on each wall block showing it's bbox. Likewise, attach a label to your player node,and display it's bbox. The color of the label for each wall should change depending on whether it interests the player bbox (and maybe a color to indicate whether it interests the top, bottom, left or right), or draw lines showing which edges are touching, etc)

      One thing that you do need to watch out for is that, IIRC, bbox or frame is with respect to the parent node. So if your walls are all children to a ground node, but your player is child of the root scene, their coordinate systems might have an offset that you have to account for. Also, if you are using scale or other tranaforms, that can change what these return...

      Is your character walking through all walls, or does it eventually stop, say after it is halfway or all the way inside the wall? There could be issues with where you have your anchor point set.

      I am now seeing this. Maybe I just wasn’t moving the sprite around enough to see it but there are definitely places where my left button wont work for large swathes of the screen and then it will start to work again once I get above a certain point. I have my sprite scaled down to 80%, but that can’t account for the position being off by 1/3 of the screen...how can i display the bbox’s? I’m not sure I know how to even do that...

      posted in Pythonista
      timjhinton
      timjhinton
    • RE: Collisions

      @JonB said:

      Actually, I think I see the issue:

      for wall in self.wall_list:
                              if new_x in wall.bbox:
                                  pass
                              else:   
                                  self.player1.position = (new_x, self.player1.position.y)
               
      

      Suppose there are two walls. The player intersects wall 1, but not wall 2. Your code will pass when checking wall1, but the next loop it will not interest wall2, and thus sets the new position.

      Thus, you need to check all walls first, and then if any intersect, disallow the move.

      allow_move=True
      for wall in self.wall_list:
          if new_x in wall.bbox:
              allow_move=False
              break # short circuit once a hit is found
      if allow_move:
          self.player1.position = (new_x, self.player1.position.y)
      

      There is probably an efficient way to do this using the any function and an iterator, which will do the proper short circuit logic, in a compact form.

      Something like (I haven't tried this, the syntax might not be quite right)

      if not any(( w.bbox.intersects(newbbox) for w in self.walls) ):
          # move player
      

      Also tried to copy and paste your first suggestion, the part without using the any function, with no success. The sprite node is still walking through walls..do i have something fundamentally wrong with how I’m doing this?

      posted in Pythonista
      timjhinton
      timjhinton
    • RE: Collisions

      @mikael said:

      @timjhinton, also, if you have just four walls, would seem simpler to have a rectangle that defines the area inside the walls, and restrict player position to be within that rectangle (by making a ”tentative” change to the coordinates and using Rect.contains_point to check if it can be really applied). This has the additional benefit that the check code can be shared by all of the four buttons.

      (Thanks for a well-presented question!)

      Thanks!
      I did set up the overall dimensions of the rectangle with only allowing the sprite to move in certain x and y limits. I have this sprite going through a small maze, so i have other walls present besides the outside 4 walls. This is where i am having the trouble. I dont want to have to hard limit every wall space on the screen.

      posted in Pythonista
      timjhinton
      timjhinton
    • RE: Collisions

      @JonB Fantastic idea. I tried to implement your suggestion by putting in another method so i could run it through easy for each of the buttons like so:

      def player_collision(self, new_xy):
      		for wall in self.wall_list:
      			if new_xy in wall.bbox:
      				return False
      			else:
      				return True
      

      Then in my update(self) section i put

      if touch.location in self.left_button.bbox:
      				new_x = self.player1.position.x - 3
      				if 50 <= new_x <= 1150:
      					if self.player_collision(self.player1.position(new_x, self.player1.position.y)) == True:
      						self.player1.position = (new_x, self.player1.position.y)
      

      I thought that this should work but it doesn’t like it. It gives me a TypeError: ‘Point” object is not callable. I’m not exactly sure what that means, but it sounds like I need to use a bbox or frame instead of player1.position??

      posted in Pythonista
      timjhinton
      timjhinton
    • RE: Collisions

      Yes, it would. I’ll probably make that change. Thanks

      posted in Pythonista
      timjhinton
      timjhinton