Display-O-Tron fixed redraw ? + button shim


#1

Hi,

I’m trying to add table RPG plugins to the Display-O-Tron menu but i have 2 problems :

  1. I made a simple random dice plugin but when i call the redraw method, it generates a new dice at each drawcall and i can’t figure out how to call it only once at a time.
  2. Id’like to add buttonshim to quickly go to some parts of the dot menu, but how to do it ?

Here is the dices file (which is added to the plugins folder and called in the menu.py)

#!/usr/bin/env python3

from random import randint as rng
from dot3k.menu import MenuOption
class Dices(MenuOption):

def __init__(self, dice):
    self.which_dice = dice

    MenuOption.__init__(self)


def dice(self):
    score = rng(1, self.which_dice)
    return score


def redraw(self, menu):
    menu.write_row(0, "      D{} :".format(self.which_dice))
    menu.clear_row(1)
    menu.write_row(2, "       {}".format(self.dice()))

Thanks for your help. :)


#2

From what I can see, redraw calls dice, which in turn calculates a new random dice value each time it is called. Move thescore= assignment into the __init__ constructor, so that the dove value is only determined once.


#3

Thanks for the answer,

Unfortunately, when i do that i got an attribute error…

AttributeError: ‘Dices’ object has no attribute ‘score’

I tried indenting the entire method, there’s an error also…


#4

Self is so easy to forget…

It kinda works but it generates only one dice of each !
Even going back to the root of the menu isn’t helping to create a new number.

Any idea ?


#5

Display-O-Tron menus can have a begin method which does something when they’re entered. Just create a new def begin(self) method and call the method to re-generate the dice roll there.


#6

Thank you Phil, you made my day. :D
…Until next time !