How do I use a BMFont as a text style property?

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
fayknaim
Newbie
Posts: 11
Joined: Fri Oct 01, 2021 11:33 am
Contact:

How do I use a BMFont as a text style property?

#1 Post by fayknaim »

I've created a BMFont that I want to use as the font for a text statement in screen language.

The documentation explains how to do this: https://www.renpy.org/doc/html/style_pr ... perty-font
font - string
A string giving the name of the font used to render text.

For a TrueType font file, this is usually the name of the file containing the font (like "DejaVuSans.ttf"). To select a second font in a collection, this can be prefixed with a number and at sign (like "0@font.ttc" or "1@font.ttc"). For an image-based font, this should be the name used to register the font.
So I should be able to use the name of the BMFont that I registered, but this doesn't seem to work for me.

Here's an example:

Code: Select all

init python:
    renpy.register_bmfont("bmfont", 50, filename="gui/bmfont.fnt")

screen bmfont_text:
    text "hello world":
        align 0.5,0.5
        font "bmfont"
 
 label start:
    show screen bmfont_text
    pause
    return
Here's the traceback:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 24, in script
    pause
  File "renpy/common/000statements.rpy", line 455, in execute_pause
    renpy.pause()
Exception: Could not find font u'bmfont'.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 24, in script
    pause
  File "renpy/ast.py", line 2010, in execute
    self.call("execute")
  File "renpy/ast.py", line 1998, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "renpy/statements.py", line 278, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 455, in execute_pause
    renpy.pause()
  File "renpy/exports.py", line 1561, in pause
    rv = renpy.ui.interact(mouse='pause', type='pause', roll_forward=roll_forward, pause=delay)
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3276, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3793, in interact_core
    self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
  File "renpy/display/core.py", line 2521, in draw_screen
    renpy.config.screen_height,
  File "render.pyx", line 492, in renpy.display.render.render_screen
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/layout.py", line 814, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/layout.py", line 814, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/layout.py", line 814, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/screen.py", line 681, in render
    child = renpy.display.render.render(self.child, w, h, st, at)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/layout.py", line 814, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/text/text.py", line 2060, in render
    virtual_layout = Layout(self, width, height, renders, drawable_res=False, size_only=True)
  File "renpy/text/text.py", line 639, in __init__
    glyphs = ts.glyphs(s, self)
  File "renpy/text/text.py", line 248, in glyphs
    fo = font.get_font(self.font, self.size, self.bold, self.italic, 0, self.antialias, self.vertical, self.hinting, layout.oversample)
  File "renpy/text/font.py", line 699, in get_font
    face = load_face(fn)
  File "renpy/text/font.py", line 640, in load_face
    raise Exception("Could not find font {0!r}.".format(orig_fn))
Exception: Could not find font u'bmfont'.

Windows-10-10.0.19041
Ren'Py 7.4.8.1895
BMFont 1.0
Sat Oct  9 00:40:54 2021
Here is a separate post with more detail about the BMFont I'm using: viewtopic.php?f=8&t=63298

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: How do I use a BMFont as a text style property?

#2 Post by jeffster »

Just as an experiment, did you try to use the font name without quotes?

Code: Select all

    font bmfont

fayknaim
Newbie
Posts: 11
Joined: Fri Oct 01, 2021 11:33 am
Contact:

Re: How do I use a BMFont as a text style property?

#3 Post by fayknaim »

That was a good experiment - but it looks like a similar error.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 28, in script
    pause
  File "renpy/common/000statements.rpy", line 455, in execute_pause
    renpy.pause()
  File "game/script.rpy", line 13, in execute
    screen bmfont_text:
  File "game/script.rpy", line 13, in execute
    screen bmfont_text:
  File "game/script.rpy", line 14, in execute
    text "hello world":
  File "game/script.rpy", line 14, in keywords
    text "hello world":
  File "game/script.rpy", line 16, in <module>
    font bmfont
NameError: name 'bmfont' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 28, in script
    pause
  File "renpy/ast.py", line 2010, in execute
    self.call("execute")
  File "renpy/ast.py", line 1998, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "renpy/statements.py", line 278, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 455, in execute_pause
    renpy.pause()
  File "renpy/exports.py", line 1561, in pause
    rv = renpy.ui.interact(mouse='pause', type='pause', roll_forward=roll_forward, pause=delay)
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3276, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3694, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/screen.py", line 432, in visit_all
    callback(self)
  File "renpy/display/core.py", line 3694, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/screen.py", line 443, in per_interact
    self.update()
  File "renpy/display/screen.py", line 631, in update
    self.screen.function(**self.scope)
  File "game/script.rpy", line 13, in execute
    screen bmfont_text:
  File "game/script.rpy", line 13, in execute
    screen bmfont_text:
  File "game/script.rpy", line 14, in execute
    text "hello world":
  File "game/script.rpy", line 14, in keywords
    text "hello world":
  File "game/script.rpy", line 16, in <module>
    font bmfont
NameError: name 'bmfont' is not defined

Windows-10-10.0.19041
Ren'Py 7.4.8.1895
BMFont 1.0
Sat Oct  9 09:44:54 2021
The BMFont is definitely registered - I can use it as the font of a Character to stylize the dialogue text.
Image

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How do I use a BMFont as a text style property?

#4 Post by PyTom »

You want to put the name in quotes.

Code: Select all

font "bmfont"
[/quote]

Or whatever you have it registered as. 

BMFonts are kind of a bad idea by modern standards, as they blur out when the window is scaled.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How do I use a BMFont as a text style property?

#5 Post by PyTom »

You want to put the name in quotes.

Code: Select all

font "bmfont"
Or whatever you have it registered as.

BMFonts are kind of a bad idea by modern standards, as they blur out when the window is scaled.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

fayknaim
Newbie
Posts: 11
Joined: Fri Oct 01, 2021 11:33 am
Contact:

Re: How do I use a BMFont as a text style property?

#6 Post by fayknaim »

Unfortunately this doesn't work for me. I started with using "bmfont" in double quotes, as written in the original post. Removing the double quotes was only a later experiment.

I see that using a BMFont in Ren'Py is not advised. Although I haven't used it much, the downsides are apparent. Still, for my purposes, I would like to play around with it - at least to get the basics down.

Post Reply

Who is online

Users browsing this forum: Google [Bot]