So I'm running in a bit of problem with buttons becoming selected. Here's the code
First, the class:
So far so good, but here's the problem:
First, I tried:
However, it got an error:
So, I tried:
Well, this works, kinda. It causes all the buttons to be selected, no matter which one I clicked on. What I want is that only the button that I clicked on got selected, the rest stay untouched.
Is there a way to do this? Or I have to define every button manually instead of doing "for q in quirkList"?
First, the class:
Python:
init python:
class Quirks(object):
def __init__ (self, name, cfname, isUnlocked, isActive, isSelected, baseDmg, quirkType):
self.name = name
self.cfname = cfname
self.isUnlocked = isUnlocked
self.isActive = isActive
self.isSelected = isSelected
self.baseDmg = baseDmg
self.quirkType = quirkType
Python:
label variable:
python:
choosenQuirk = set([])
quirkList = []
quirkList.append(Quirks("Gravity", "gravity", True, True, False, 10, "physical"))
quirkList.append(Quirks("Explosion", "explosion", True, True, False, 20, "physical"))
quirkList.append(Quirks("Frog", "frog", True, True, False, 15, "physical"))
return
First, I tried:
Code:
frame:
xsize 1920
ysize 300
ypos 780
background "#cc9e25"
hbox:
for q in quirkList:
if q.isUnlocked:
textbutton q.name:
action [ToggleVariable(q.isSelected, True, False), SelectedIf(q.isSelected == True), ToggleSetMembership(choosenQuirk, q.cfname)]
Code:
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 32, in script
call screen mainUI
File "renpy/common/000statements.rpy", line 531, in execute_call_screen
store._return = renpy.call_screen(name, *args, **kwargs)
File "renpy/common/00action_data.rpy", line 222, in __call__
__set_field(self.object, self.field, value, self.kind)
File "renpy/common/00action_data.rpy", line 44, in _m1_00action_data__set_field
fields, _, attr = name.rpartition(".")
AttributeError: 'bool' object has no attribute 'rpartition'
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 32, in script
call screen mainUI
File "D:\Renpy\renpy\ast.py", line 1949, in execute
self.call("execute")
File "D:\Renpy\renpy\ast.py", line 1937, in call
return renpy.statements.call(method, parsed, *args, **kwargs)
File "D:\Renpy\renpy\statements.py", line 277, in call
return method(parsed, *args, **kwargs)
File "renpy/common/000statements.rpy", line 531, in execute_call_screen
store._return = renpy.call_screen(name, *args, **kwargs)
File "D:\Renpy\renpy\exports.py", line 2905, in call_screen
rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
File "D:\Renpy\renpy\ui.py", line 297, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "D:\Renpy\renpy\display\core.py", line 2702, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
File "D:\Renpy\renpy\display\core.py", line 3518, in interact_core
rv = root_widget.event(ev, x, y, 0)
File "D:\Renpy\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "D:\Renpy\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "D:\Renpy\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "D:\Renpy\renpy\display\screen.py", line 714, in event
rv = self.child.event(ev, x, y, st)
File "D:\Renpy\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "D:\Renpy\renpy\display\layout.py", line 244, in event
rv = d.event(ev, x - xo, y - yo, st)
File "D:\Renpy\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "D:\Renpy\renpy\display\behavior.py", line 962, in event
return handle_click(self.clicked)
File "D:\Renpy\renpy\display\behavior.py", line 897, in handle_click
rv = run(action)
File "D:\Renpy\renpy\display\behavior.py", line 313, in run
new_rv = run(i, *args, **kwargs)
File "D:\Renpy\renpy\display\behavior.py", line 320, in run
return action(*args, **kwargs)
File "renpy/common/00action_data.rpy", line 222, in __call__
__set_field(self.object, self.field, value, self.kind)
File "renpy/common/00action_data.rpy", line 44, in _m1_00action_data__set_field
fields, _, attr = name.rpartition(".")
AttributeError: 'bool' object has no attribute 'rpartition'
Windows-8-6.2.9200
Ren'Py 7.3.5.606
Combat system test 1.0
Wed Sep 16 10:29:35 2020
default buttonSelected = False
Code:
frame:
xsize 1920
ysize 300
ypos 780
background "#cc9e25"
hbox:
for q in quirkList:
if q.isUnlocked:
textbutton q.name:
action [ToggleVariable(buttonSelected, True, False), SelectedIf(buttonSelected == True), ToggleSetMembership(choosenQuirk, q.cfname)]
Is there a way to do this? Or I have to define every button manually instead of doing "for q in quirkList"?