World > Console#

API Reference#

Console#

class miniworlds.worlds.gui.console.Console(*args, **kwargs)[source]#

A scrolling text console that can be docked to a world.

Use console.newline(text) to append lines of text. The console is a special Toolbar that is typically docked below or beside the main world using world.camera.add_bottom(console) or world.camera.add_right(console).

Only the last max_lines lines are kept: when the console is full, the oldest line is removed, so the console’s memory use stays constant even if newline is called every frame.

Examples

console = Console()
world.camera.add_bottom(console)

@world.register
def act(self):
    console.newline("Frame: " + str(world.frame))
__init__()[source]#

Creates a console toolbar with compact text rows.

The console starts with a small default height and is intended for short log messages such as score changes, instructions, or debug output.

dialog#
newline(text)[source]#

Appends a new line of text to the console.

Each call adds one label row. When more than max_lines lines exist, the oldest line is removed and the remaining lines move up.

Return type:

Label

Parameters:

text – The text string to display on the new line.

Returns:

The Label actor that was created for this line.

Examples

console.newline("Player position: " + str(player.position))

PagerHorizontal#

class miniworlds.worlds.gui.pager.PagerHorizontal(*args, **kwargs)[source]#

Toolbar with scroll buttons for another toolbar or console.

The pager shows an up and a down button and toggles their visibility depending on whether the observed GUI can still scroll in that direction.

Parameters:

gui – The toolbar or console whose scroll range is controlled.

act()[source]#

Hook: called once per frame while the world is running.

Overwrite this method in a subclass (or register a function with @world.register) to run code every frame.

The base implementation does nothing, so super().act() is never required in an overwritten act method.

Examples

class MyWorld(World):
    def act(self):
        if self.frame % 60 == 0:
            self.spawn_enemy()
dialog#
on_setup()[source]#

Hook for initial world setup.

Override this in subclasses or register a function with @world.register.

Examples

@world.register
def on_setup(self):
    self.background = (0, 0, 0)
    Actor((20, 20))