Hello!
I made a previous post about making a fake in-game radio for my horror game. How it works is that the radio is a composite of a few screens for display, with a slider bar that "tunes" the radio, either playing static or music. The station number cooresponds to a track that plays on the radio, which displays as you move the slider. Also, there's a button that will either become a play or pause button, and a button to leave the screen. So far, it works! The audio changes when you slide the bar, and the station changes in real time above it, which has been cool so far. Here's what it looks like all together (doesn't look pretty yet lmao):
Aaaaaand here's the code I made for it:
Code: Select all
screen Leave:
frame:
align (.6,.9)
padding (20,10)
textbutton "CLOSE" action Jump("AnotherDay"):
activate_sound "audio/typeClick.mp3"
init python:
global signal
import renpy.audio.music as music
music.register_channel("music_room", mixer="music_room_mixer", loop=True)
pausedstate = True
def playSignal():
global pausedstate
if pausedstate == False:
if persistent.signal == 2:
renpy.music.play("audio/signal1.ogg", channel="music_room", loop=True, fadein=1.0)
elif persistent.signal == 5:
renpy.music.play("audio/signal2.ogg", channel="music_room", loop=True, fadein=1.0)
elif persistent.signal == 11:
renpy.music.play("audio/signal3.ogg", channel="music_room", loop=True, fadein=1.0)
elif persistent.signal == 14:
renpy.music.play("audio/signal4.ogg", channel="music_room", loop=True, fadein=1.0)
elif persistent.signal == 9:
sig.Play("audio/signal5.ogg")
renpy.music.play("audio/signal5a.ogg", channel="music_room", loop=True, fadein=1.0)
else:
renpy.music.play("audio/signal-static.ogg", channel="music_room", loop=True)
return
def pauseSignal():
global pausedstate
music.stop(channel='music_room', fadeout=1.0)
define signals = [
101.1, 101.2, 101.3, 101.4,
102.1, 102.2, 102.3, 102.4,
103.1, 103.2, 103.3, 103.4,
104.1, 104.2, 104.3, 104.4
]
default persistent.signal = 0
default stationNum = persistent.signal
default currentSignal = signals[stationNum]
default current_signal = None
transform gestaltButton:
on hover:
alpha 1
on idle:
alpha .5
screen radioBar:
bar:
value FieldValue(persistent, "signal", 15, style="radio_slider", step=1, force_step = False)
align (.5,.5)
xsize 300
ysize 35
thumb "gui/slider/rad_thumb.png"
thumb_offset 32
left_gutter 13
right_gutter 13
screen playpause():
if pausedstate:
imagebutton:
at gestaltButton
xalign .5
idle buttonPlay
hover buttonPlay
action ToggleVariable("pausedstate"), PauseAudio(channel='music_room', value=False)
if not pausedstate:
imagebutton:
at gestaltButton
xalign .5
idle buttonPause
hover buttonPause
action ToggleVariable("pausedstate"), PauseAudio(channel='music_room', value=True)
screen cellRadio():
$ stationNum = persistent.signal
$ currentSignal = signals[stationNum]
if not pausedstate:
$ playSignal()
frame:
align (0.5,0.5)
padding (50,150)
vbox:
ypos -50
spacing 30
frame:
padding (50,10)
align (.5,.5)
text "S I G N A L"
frame:
align (.5,.5)
padding (50,20)
text "[currentSignal]" size 100 font "fonts/digital-7.ttf"
use radioBar
use playpause
use Leave
label radioScreen:
call screen cellRadio
return
Here's my issue: Whenever I leave this screen, or do anything else really, the music that's playing from the radio replays itself automatically. If I pause the game (normal right click) and unpause, the track playing will restart. Other times, it will restart from the very start of the track list (101.1, in this case) without me touching it. This is an issue because I need the music to continue to play after closing the screen, and while checking other screens. The only way I want this to change is with the play/pause button (it becomes one or the other when pressed), and while it successfully turns off/on the radio, the issue is that it's not a true pause, and will instead stop the music when paused, and play it from the beginning when played. Basically, the same issue.
TROUBLESHOOTING:
I think it may be an issue with me running the $ playSignal() command in my screen, and why it's restarting every time. However, I want the tracks to change in real time with the slider, so I need something there that tracks and changes what is playing, which is what that function does. Also, I'm trying to use the traditional PauseAudio() action for the play/pause button (was using 'stop' actions before), but it essentially does nothing so far. The same thing goes for the pauseSignal() function, which does the same thing whether it's using a 'stop' or 'pause' command (which is why it's not being used right now). I really think the issue is either with the channel the radio uses ('music_room' in this case), or the fact that the playSignal() function uses renpy.music.play to play the tracks when called, which may be why it restarts everytime I come back to this screen? The problem is, I don't know what other action to use here, nor do I know how to get a proper pause that stops the track rather than replaying it. I'm a little stuck, haha.
Got a killer response from the forums last time, so I'm hoping for some good luck again by posting the issue here. Hopefully someone may know what to do here, I'm an animator first and foremost and still getting the hang writing code like this lol. Big thanks in advance!