So let's say we have a...
Code: Select all
default switch = buttons("button_1", 0, 1, 0 ,4 , 5, 0} #in sequence: image, and other corresponding values
screen value_screen:
vbox:
text "[value_1]
text "[value_2]
text "[value_3]
Code: Select all
default switch = buttons("button_1", 0, 1, 0 ,4 , 5, 0} #in sequence: image, and other corresponding values
screen value_screen:
vbox:
text "[value_1]
text "[value_2]
text "[value_3]
Not sure I'm following. You also have typos in your code. What is this "buttons" class anyway? It's not a dict, that's for sure. You have to post the corresponding class if you need help.
The class itself isn't too complex. Just a placeholder for test purposes.m_from_space wrote: ↑Sat Jan 27, 2024 10:12 am Not sure I'm following. You also have typos in your code. What is this "buttons" class anyway? It's not a dict, that's for sure. You have to post the corresponding class if you need help.
Code: Select all
init python:
class buttons:
def __init__(self, img, place1, place2, place3, place4, place5, place6):
self.img = img
self.place1= place1
self.place2= place2
self.place3= place3
self.place4= place4
self.place5= place5
self.place6 = place6
Code: Select all
init python:
class buttons:
def __init__(self, img, place1, place2, place3, place4, place5, place6):
self.img = img
self.places = [place1, place2, place3, place4, place5, place6]
# Or even
def __init__(self, img, *args):
self.img = img
assert len(args) == 6
self.places = list(args)
Code: Select all
def extract_non_zero(self):
return filter(None, self.places) # This returns a list of non-zero numbers
Code: Select all
screen value_screen:
vbox:
for item in switch.extract_non_zero():
text str(item)
For the first method it gives me an error saying that 'name switch" is not definiedOcelot wrote: ↑Thu Feb 01, 2024 3:38 amCode: Select all
init python: class buttons: def __init__(self, img, place1, place2, place3, place4, place5, place6): self.img = img self.places = [place1, place2, place3, place4, place5, place6] def extract_non_zero(self): return filter(None, self.places) # This returns a list of non-zero numbers screen value_screen: vbox: for item in switch.extract_non_zero(): text str(item)
I was relying on code you have shown, and switch was defined there...
It's something I realized just by now, but the extract_non_zero method doesn't update it's value as one of the buttons are changed. Maybe 'cause it's pre-defined or I overlooked something with my code. If I'm right with the first case, is there a way to fit it into updated values?Ocelot wrote: ↑Thu Feb 01, 2024 3:38 amCode: Select all
screen value_screen: vbox: for item in switch.extract_non_zero(): text str(item)
Users browsing this forum: No registered users