Ren'Py Change class variables for the music room (Toggle button)

Playstorepers

Member
May 24, 2020
160
79
Hey everyone,

Let's say I created a music room and I want to add the play on repeat and shuffle function with toggle buttons.



How would one do that?
From my understanding the musicroom class (in my case, the music room is called mr), has two variables (single_track and shuffle), that I want to change with a toggle button.
So my first impulse was this:

Python:
frame:
        xalign 0.5
        yalign 0.5
        textbutton "Listen on repeat" action If (mr.single_track == False; mr.single_track = True; mr.single_track == False)
However, the mr.single_track doesn't work, which means, that class variables have to be changed differently is that correct?
Does anyone have a working toggle button for their music room and is willing to share their code with me?

Thanks in advance.

EDIT: I'm a useless piece of shit. Right beneath the documentation is a section that mentions two functions:
ToggleSingleTrack(self)

ToggleShuffle(self)

EDIT 2:
Still... Does anyone know why this:
textbutton "Listen on repeat" action If (mr.single_track == False; mr.single_track = True; mr.single_track = False)
doesn't work?
How do I change class variables correctly?
 
Last edited:

Playstorepers

Member
May 24, 2020
160
79
thank you.


that was my first mistake my second one was == instead of = for the false portion.
However it still doesn't work, most likely because textbuttons can't change variables directly, right?
So I tried:

textbutton "Listen on repeat" action If (mr.single_track == False, SetVariable(mr.single_track,True), SetVariable(mr.single_track,False))
and it still doesn't work.

action mr.ToggleSingleTrack() works like a charm, though, yet still I'm curious, how exactly I change class variables.
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,490
7,035
textbutton "Listen on repeat" action If (mr.single_track == False, SetVariable(mr.single_track,True), SetVariable(mr.single_track,False))
and it still doesn't work.
You want SetField not SetVariable


Code:
textbutton "Listen on repeat" action If (mr.single_track == False, SetField(mr, "single_track" ,True), SetField(mr, "single_track", False))
Or, more easily

Code:
textbutton "Listen on repeat" action ToggleField(mr, "single_track")
 
  • Like
Reactions: Playstorepers