Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
-
deltadidirac
- Regular
- Posts: 123
- Joined: Fri Nov 30, 2018 5:00 am
- Projects: Artworks and Comics
- Tumblr: deltadidirac
- Deviantart: Deltadidirac67
- Location: Europe
-
Contact:
#1
Post
by deltadidirac » Fri Nov 30, 2018 5:13 am
Hi all,
503/5000
I apologize for my bad English and I state that I am an artist and not a programmer, it is the first time that I see a programming code ...
My problem is this:
I would like to play a sound when my personal "user Iterface" screen appears and stop it when the the screen closes, but after many tests and attempts I did not understand how I should do, I looked at other topics but I could not find anything; I write below the code of my screen and thanks in advance for the answers.
Code: Select all
screen interface:
zorder 200
add "nmap"
imagebutton:
idle "mappa_id"
hover "mappa_ho"
action [Hide ("interface"), Show ("building1")]
xpos 83
ypos 59
imagebutton:
idle "bloc_id"
hover "bloc_ho"
action [Hide ("interface"), Show ("building1")]
xpos 821
ypos 52
hbox:
xpos 495 ypos 68
if dval ==0:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday0]"
elif dval ==1:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday1]"
elif dval ==2:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday2]"
elif dval ==3:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday3]"
elif dval ==4:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday4]"
elif dval ==5:
hbox:
text "{b}{u}{size=18}{color=#aeac44}[nday5]"
elif dval ==6:
hbox:
text "{b}{u}{size=18}{color=#de1d2d}[nday6]"
else:
hbox:
text "{b}{u}{size=18}{color=#de1d2d}error"
Last edited by
deltadidirac on Sun Dec 02, 2018 11:50 am, edited 1 time in total.
-
Enchant00
- Regular
- Posts: 136
- Joined: Tue Jan 12, 2016 1:17 am
-
Contact:
#2
Post
by Enchant00 » Fri Nov 30, 2018 2:04 pm
Try this:
Code: Select all
screen interface:
zorder 200
add "nmap"
imagebutton:
idle "mappa_id"
hover "mappa_ho"
action [Hide ("interface"), Show ("building1")]
xpos 83
ypos 59
imagebutton:
idle "bloc_id"
hover "bloc_ho"
action [Hide ("interface"), Show ("building1")]
xpos 821
ypos 52
hbox:
xpos 495 ypos 68
if dval ==0:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday0]"
elif dval ==1:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday1]"
elif dval ==2:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday2]"
elif dval ==3:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday3]"
elif dval ==4:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday4]"
elif dval ==5:
hbox:
text "{b}{u}{size=18}{color=#aeac44}[nday5]"
elif dval ==6:
hbox:
text "{b}{u}{size=18}{color=#de1d2d}[nday6]"
else:
hbox:
text "{b}{u}{size=18}{color=#de1d2d}error"
on 'Show' action Play('music', your_music.mp3, loop = True)
on 'Hide' action Stop('music', fadeout = 1.0)
Change the your_music.mp3 to the filename of your music.
-
deltadidirac
- Regular
- Posts: 123
- Joined: Fri Nov 30, 2018 5:00 am
- Projects: Artworks and Comics
- Tumblr: deltadidirac
- Deviantart: Deltadidirac67
- Location: Europe
-
Contact:
#3
Post
by deltadidirac » Fri Nov 30, 2018 3:15 pm
Thanks Enchante00 for the answer,
I wrote your suggest, but nothing happend...
perhaps i forgot to unblock some options or gui customizations or... i don't know
see you
-
Per K Grok
- Miko-Class Veteran
- Posts: 882
- Joined: Fri May 18, 2018 1:02 am
- Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
- itch: per-k-grok
- Location: Sverige
-
Contact:
#4
Post
by Per K Grok » Fri Nov 30, 2018 6:20 pm
deltadidirac wrote: ↑Fri Nov 30, 2018 5:13 am
I would like to play a sound when my personal "user Iterface" screen appears and stop it when the the screen closes,
You could start and stop the music in connection with the commands to show and hide the screen
show screen interface
play music "your_music.ogg"
-------
hide screen interface
stop music
-
Enchant00
- Regular
- Posts: 136
- Joined: Tue Jan 12, 2016 1:17 am
-
Contact:
#5
Post
by Enchant00 » Sat Dec 01, 2018 6:59 am
deltadidirac wrote: ↑Fri Nov 30, 2018 3:15 pm
Thanks Enchante00 for the answer,
I wrote your suggest, but nothing happend...
perhaps i forgot to unblock some options or gui customizations or... i don't know
see you
I'm sorry. It's my mistake the code should be the one below:
Code: Select all
on 'show' action Play('music', your_music.mp3, loop = True)
on 'hide' action Stop('music', fadeout = 1.0)
Show and
Hide should be in lower case
show and
hide
Another solution is also to just play the music before and after your screen declaration:
Code: Select all
e 'some text'
play music 'your_music.mp3'
show screen your_screen
stop music
However, I think the code above is what you are looking for if you don't want to declare the play music and stop music all the time.
-
deltadidirac
- Regular
- Posts: 123
- Joined: Fri Nov 30, 2018 5:00 am
- Projects: Artworks and Comics
- Tumblr: deltadidirac
- Deviantart: Deltadidirac67
- Location: Europe
-
Contact:
#6
Post
by deltadidirac » Sat Dec 01, 2018 12:37 pm
hi,
yes thanks, it run in this way.
now since the background song is a song and not a sound, I have to understand how to start the music piece only once, until you start a new label, otherwise at each "show" and "hide", the song starts again from head.
If I was capable, I would build a function, probably it would be more simple...
-
Enchant00
- Regular
- Posts: 136
- Joined: Tue Jan 12, 2016 1:17 am
-
Contact:
#7
Post
by Enchant00 » Sun Dec 02, 2018 4:46 am
Before you show your screen put this
Remove the
on hide... line and change the
on show (don't forget to change test.mp3 to your desired track):
Code: Select all
on "show" action If(played_once, false = Play('music', 'test.mp3'))
When you're done showing the screen put this:
This means that the first time you play the music track it will continue to play but not at every show and hide anymore. It will only play once and when you are in your new label you can stop the music and change the track

-
deltadidirac
- Regular
- Posts: 123
- Joined: Fri Nov 30, 2018 5:00 am
- Projects: Artworks and Comics
- Tumblr: deltadidirac
- Deviantart: Deltadidirac67
- Location: Europe
-
Contact:
#8
Post
by deltadidirac » Sun Dec 02, 2018 6:14 am
thanks Enchante00
but i think that is the same way to write play and stop in the start and in the end of every label..
it's just an intuition, but I think the right path is this:
incorporate my music as a property of the my screen object and define it as play once.
At the same time insert in the label object (whatever it is), the stop music property.
the problem is how to do it....

-
Enchant00
- Regular
- Posts: 136
- Joined: Tue Jan 12, 2016 1:17 am
-
Contact:
#9
Post
by Enchant00 » Sun Dec 02, 2018 8:06 am
Sorry I'm confused a bit so let's clarify a few things XD
So when you show your screen do you want to:
1. Play the music once every time you show your screen or
2. When you show your screen for the first time, it plays your music and the next time you show your screen it doesn't.
In addition, you want the music just to play once and not loop?
-
deltadidirac
- Regular
- Posts: 123
- Joined: Fri Nov 30, 2018 5:00 am
- Projects: Artworks and Comics
- Tumblr: deltadidirac
- Deviantart: Deltadidirac67
- Location: Europe
-
Contact:
#10
Post
by deltadidirac » Sun Dec 02, 2018 8:30 am
sorry if I have not written well before ...
-My game (like others), brings up the UI screen when a scene is finished and continues to remain visible (regardless of where you go), until you unlock the next scene or because you have done an action (like buying an Item ) or because you are in a given place at a given time.
-so, every time the UI screen appears I want to start the piece of music (which lasts 4.5 minutes, so you do not need the loop or at most 2 times) and stop only at the beginning of the new scene and not when you are moving around the locations or in the main map.
-And so on
I hope it's more clear now
-
Enchant00
- Regular
- Posts: 136
- Joined: Tue Jan 12, 2016 1:17 am
-
Contact:
#11
Post
by Enchant00 » Sun Dec 02, 2018 9:33 am
Ok, I understand now:
Code: Select all
screen interface:
zorder 200
add "nmap"
imagebutton:
idle "mappa_id"
hover "mappa_ho"
action [Hide ("interface"), Show ("building1")]
xpos 83
ypos 59
imagebutton:
idle "bloc_id"
hover "bloc_ho"
action [Hide ("interface"), Show ("building1")]
xpos 821
ypos 52
hbox:
xpos 495 ypos 68
if dval ==0:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday0]"
elif dval ==1:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday1]"
elif dval ==2:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday2]"
elif dval ==3:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday3]"
elif dval ==4:
hbox:
text "{b}{size=18}{color=#5f44ff}[nday4]"
elif dval ==5:
hbox:
text "{b}{u}{size=18}{color=#aeac44}[nday5]"
elif dval ==6:
hbox:
text "{b}{u}{size=18}{color=#de1d2d}[nday6]"
else:
hbox:
text "{b}{u}{size=18}{color=#de1d2d}error"
on "show" action Play('music', 'test.ogg', loop = False) #change test.ogg to the name of your soundtrack
So, when you show the screen it only plays once.
When you are in a new scene or a new label, use the command below:
I think this should be what you are looking for

-
deltadidirac
- Regular
- Posts: 123
- Joined: Fri Nov 30, 2018 5:00 am
- Projects: Artworks and Comics
- Tumblr: deltadidirac
- Deviantart: Deltadidirac67
- Location: Europe
-
Contact:
#12
Post
by deltadidirac » Sun Dec 02, 2018 9:37 am
Yes,
I think that now it's the more simple solution.
Thanks
see you
Users browsing this forum: Majestic-12 [Bot]