Health Bar

Contrib - Tim Ashley Jenkins 2017

The function provided in this module lets you easily display visual bars or meters - “health bar” is merely the most obvious use for this, though these bars are highly customizable and can be used for any sort of appropriate data besides player health.

Today’s players may be more used to seeing statistics like health, stamina, magic, and etc. displayed as bars rather than bare numerical values, so using this module to present this data this way may make it more accessible. Keep in mind, however, that players may also be using a screen reader to connect to your game, which will not be able to represent the colors of the bar in any way. By default, the values represented are rendered as text inside the bar which can be read by screen readers.

The health bar will account for current values above the maximum or below 0, rendering them as a completely full or empty bar with the values displayed within.

No installation, just import and use display_meter from this module:

from evennia.contrib.rpg.health_bar import display_meter

health_bar = display_meter(23, 100)
evennia.contrib.rpg.health_bar.health_bar.display_meter(cur_value, max_value, length=30, fill_color=['R', 'Y', 'G'], empty_color='B', text_color='w', align='left', pre_text='', post_text='', show_values=True)[source]

Represents a current and maximum value given as a “bar” rendered with ANSI or xterm256 background colors.

  • cur_value (int) – Current value to display

  • max_value (int) – Maximum value to display

Keyword Arguments
  • length (int) – Length of meter returned, in characters

  • fill_color (list) – List of color codes for the full portion of the bar, sans any sort of prefix - both ANSI and xterm256 colors are usable. When the bar is empty, colors toward the start of the list will be chosen - when the bar is full, colors towards the end are picked. You can adjust the ‘weights’ of the changing colors by adding multiple entries of the same color - for example, if you only want the bar to change when it’s close to empty, you could supply [‘R’,’Y’,’G’,’G’,’G’]

  • empty_color (str) – Color code for the empty portion of the bar.

  • text_color (str) – Color code for text inside the bar.

  • align (str) – “left”, “right”, or “center” - alignment of text in the bar

  • pre_text (str) – Text to put before the numbers in the bar

  • post_text (str) – Text to put after the numbers in the bar

  • show_values (bool) – If true, shows the numerical values represented by the bar. It’s highly recommended you keep this on, especially if there’s no info given in pre_text or post_text, as players on screen readers will be unable to read the graphical aspect of the bar.


str – The display bar to show.