Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Truncated Text for Ren'Py

Shrink or shorten text that doesn't fit its container for popups or other UI elements. · By Feniks

Need Support? Post here! Sticky

A topic by Feniks created 53 days ago Views: 59 Replies: 6
Viewing posts 1 to 2
Developer

If you're having trouble or run into any bugs with the code, post a comment here! I will try to get back to you within a few days.

(1 edit)

Hi there! No matter where I put 01_truncate_text.rpy, it doesn't seem to want to run before my "screens.rpy" file and causes the below error whenever I want to use it:


If I remove my own use case, I can try things out with test_truncate_text just fine, though. Any idea how to fix this?

Developer(+1)

Remember Ren'Py loads files in ASCII order - so, if you've got 01_truncate_text.rpy inside a folder, it'll run based on the folder name.

Aka something like game/backend/01_truncate_text.rpy runs AFTER game/accessibility.rpy (so you couldn't use truncate_text inside accessibility.rpy).

I did request a special lib folder for the next version of Ren'Py, but at the moment your best bet is putting external libraries that need to run first inside a folder called something like 01_libraries/ so they run before your other files.

Thank you, that did the trick!

Alright, now I've successfully caused a new problem:

So far, truncate_text runs fine until it actually has to cut something off. Whenever I set ysize or a surrounding fixed to a value smaller than what could contain the full text, it throws the error above. For example:

truncate_text last_phrase text_size 20 ysize 30

Here, last_phrase gets information attached to each save file and is defined on the save screen:

$ last_phrase = FileJson(slot, "last_line", empty="", missing=" ")

While "last_line" is obtained like this:

def the_lastline(d):
      mylast_line = getattr(store, '_last_raw_what', '',)
      if not mylast_line:
          mylast_line = getattr(store, '_last_choice_what', '',)
      if mylast_line == "ending":
          line_take = str(len(true_endings))+ _("/14 Rehabilitated")
      else:
          line_take = renpy.substitute(renpy.filter_text_tags(mylast_line, allow=[]))
          line_take = line_take.replace("\n", "")
          line_take = line_take.replace("\\", "")
          line_take = "\"" + line_take + "\""
          if line_take == "\"\"":
              line_take = ""
      d["last_line"] = line_take 

I don't really know what's going on here, but I could imagine "_last_raw_what" is the issue (getting dialogue text instead of "normal" text). 

Any idea for a workaround to make it compatible with truncate_text?

Developer(+1)

Actually I think this is a very funny one - do you have a character named re? That's the name I imported the regex library under. I should probably put this in a separate namespace to avoid this kind of issue lol. If that's the case,  then you can update `import re` to `import re as regex` and change all the `re.` method calls to `regex.` method calls.

That was it, thank you! It works perfectly now.