When multiple windows contain text beginning with the same word, only the last window is displayed

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
apple_spider
Newbie
Posts: 4
Joined: Mon Mar 14, 2022 9:22 pm
Contact:

When multiple windows contain text beginning with the same word, only the last window is displayed

#1 Post by apple_spider »

My game has small notification windows that rise up the screen and fade away to inform the player about stat changes and tests or provide other information. If several windows are displayed at the same time, they are automatically spaced out so they don't overlap.

For the most part, this code works as expected - even when there are multiple windows onscreen at once.

However, if two windows include text that begins with the same word, only the last one is displayed. I have a theory about what might be causing this (perhaps Ren'Py interprets that word as a tag to one of the elements, and will only show one element at a time for a given tag?) but haven't been able to find a relevant section in the documentation. I've tried unsuccessfully to add a "tag=" argument to some of the displayables and see if I can find one that's the source of the problem - and maybe pass unique tag values to - but haven't had any luck so far.

Here is some code that demonstrates the problem.

Code: Select all

transform bubble_move(txt, ypos, background="000",delay=0,style_name="bubble_window",yoffset=-200,xadjust=0.5):
  #Makes sure bubbles are spaced out and don't overlap
  time delay

  Window(Text(txt, size=20), style_name)
  ypos ypos
  #xalign 0.5
  xalign xadjust
  alpha 0.1
   
  parallel:
      linear 0.5 alpha 1.0
  parallel:
      #Speed and direction are handled by yoffset
      linear 2 yoffset -200
  parallel:
      pause 1.5
      linear 0.5 alpha 0.1
      Null()
      
init python:
  import time

  class Bubble():
    #time.time() returns seconds past the epoch

    def __init__(self):
      self.start_time = 0
      self.delay_duration = .5
      #Generally not used; it's there if I want to log what's in the bubbles
      self.debug_text = "Debugging text"
      self.xadjust = 0.1
    
    def set_timestamp(self,delay=0):
      self.start_time = time.time() + delay

    def get_timestamp(self):
      return self.start_time

    def calculate_delay(self):
      now = time.time()
      time_elapsed = now - self.get_timestamp()
      if time_elapsed > self.delay_duration:
        #renpy.log("The if: %s" % self.debug_text)
        self.set_timestamp()
        return 0
      else:
        delay = self.delay_duration - time_elapsed
        #renpy.log("The else: %.2f" % delay)
        self.set_timestamp(delay)
        return delay

    def show_bubble(self,txt,ypos,background="#000",delay=0,style_name="bubble_window",xadjust=0.5):
      #self.debug_text = txt
      bubble_delay = self.calculate_delay()
      renpy.show(txt, what=bubble_move(txt, ypos, delay=bubble_delay,style_name=style_name))
      #Used this to horizontally space bubbles during testing
      #self.xadjust += 0.1
      #if self.xadjust >= 1:
      #  self.xadjust = 0.1
      return True

    #I have several of these wrappers for the show_bubble function; they vary in style and the additional text added
    def stat_bad_decrease(self, varname):
      self.show_bubble("{} has decreased".format(varname),300,style_name="bubble_window_good")
      
      
 start:
     define bubbler = Bubble()
     "We're about to see some bubbles that demonstrate the problem."
      python:
        #This one doesn't show up
        bubbler.stat_bad_decrease("Same First")
        #This one doesn't show up, either
        bubbler.stat_bad_decrease("Same Again")
        #This one shows up
        bubbler.stat_bad_decrease("Same Third")
        #"Aggressive Micromanagement" and "Aggressive Nanomanagement" don't show up - but "Aggressive Picomanagement" does
        for bubble_label in ["Superfluous Paperwork", "Time-Wasting All-Hands Meetings", "Aggressive Micromanagement", "Tedious Weekly Reports", 
                              "Unnecessarily Verbose Procedures", "Aggressive Nanomanagement", "Inaccurate Training Materials", "Acronym Bloat",
                              "Embarrassing Slogans","Aggressive Picomanagement"]:
          bubbler.stat_bad_decrease(bubble_label)
     "Here are the bubbles."
I posted before about what I believe to be the same problem: viewtopic.php?f=8&t=64189 . In summary, some of my bubbles that included Unicode up or down arrows weren't displayed. At the time I wondered if this was a Unicode issue, because removing the arrows resolved the problem. However, I now suspect that - much as only the last window with text beginning with "Aggressive" was shown - only the last window with text beginning with an arrow (followed by a space) was shown; it's the same "non-unique first words lead to windows not being displayed" issue, but in that case the first "word" is a single arrow.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: When multiple windows contain text beginning with the same word, only the last window is displayed

#2 Post by Remix »

Code: Select all

renpy.show(txt.replace(" ", "_"), what=bubble_move(txt, ypos, delay=bubble_delay,style_name=style_name))
*should* fix your issue (as, yes it is using the text string as a widget tag identifier)

Also maybe check https://github.com/RenpyRemix/multi-notify and the Multi Notify Overview page for some info about using the index keyword in for loops to preserve ATL on looped widgets
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: No registered users