Actor > Number

Actor > Number#

class miniworlds.actors.texts.number.Number(position: Tuple[float, float] | None = (0, 0), *args, **kwargs)[source]

A number actor that displays a numeric value (integer or float).

You must manually set the size of the actor with self.size() to ensure the text fits the screen.

Parameters:
  • position (tuple) – Top-left position of the number actor.

  • number (int or float) – The initial number to display.

  • **kwargs – Additional arguments passed to the base class.

Example

Create and update a Number actor:

score = Number(position=(0, 0), number=0)
score.set_number(3)
print(score.get_number())
add(value)[source]

Add a value to the current number.

Parameters:

value (int or float) – The value to add.

Example:

number_actor.add(2)
get_number()

Get the current number.

Return type:

int

Returns:

The currently displayed number.

Return type:

int

Example:

current = number_actor.get_number()
get_value()[source]

Get the current number.

Return type:

int

Returns:

The currently displayed number.

Return type:

int

Example:

current = number_actor.get_number()
inc()[source]

Increase the number by 1.

Example:

number_actor.inc()
set_number(number)

Set the number to display.

Parameters:

number (int or float) – The number to set.

Example:

number_actor.set_number(3)
set_value(number)[source]

Set the number to display.

Parameters:

number (int or float) – The number to set.

Example:

number_actor.set_number(3)
sub(value)[source]

Subtract a value from the current number.

Parameters:

value (int or float) – The value to subtract.

Example:

number_actor.sub(5)
update_text()[source]

Update the visual text display to match the current number.

property value

Get or set the value of the number.

Returns:

The current number.

Return type:

int