Hi !
(Should i say : Hi Phil ? ;) )
Continuing my RPG journey, i came to an odd issue.
The goal is to change back the color of the backlight to violet when i leave the dices to return to the main menu)
It works fine using the ‘select’ button but not with ‘cancel’ (the code is copy/paste from one to the other).
Any idea ?
#!/usr/bin/env python3
from random import randint as rng
from dot3k.menu import MenuOption
from dothat import backlight
import dothat.touch as nav
import buttonshimclass Dices(MenuOption):
def __init__(self, dice): self.which_dice = dice self.x = 0 MenuOption.__init__(self) def begin(self): self.score = self.roll() def cancel(self): backlight.set_graph(0) backlight.rgb(255, 42, 255) buttonshim.set_pixel(0, 0, 0) return True def select(self): backlight.set_graph(0) backlight.rgb(255, 42, 255) buttonshim.set_pixel(0, 0, 0) return True def roll(self): result = rng(1, self.which_dice) return result def redraw(self, menu): if self.which_dice == 100 and self.score >95: backlight.rgb(255, 42, 42) buttonshim.set_pixel(255, 42, 42) menu.write_row(0, " D{} :".format(self.which_dice)) menu.write_row(1, " FAIL !") menu.write_row(2, " {}".format(self.score)) elif self.which_dice == 100 and self.score <=5: self.x += 3 self.x %= 360 backlight.sweep((360.0 - self.x) / 360.0) buttonshim.set_pixel(42, 255, 42) menu.write_row(0, " D{} :".format(self.which_dice)) menu.write_row(1, " EPIC !") menu.write_row(2, " {}".format(self.score)) else: backlight.rgb(255, 42, 255) buttonshim.set_pixel(255, 42, 255) menu.write_row(0, " D{} :".format(self.which_dice)) menu.clear_row(1) menu.write_row(2, " {}".format(self.score))