Lemma Soft Forums

Supporting creators of visual novels and story-based games since 2003.


Visit our new games list, blog aggregator, IRC channel, and Discord (new).
Activation problem? Email pytom@bishoujo.us.
It is currently Wed Apr 26, 2017 7:24 pm

All times are UTC - 5 hours [ DST ]


Forum rules


This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like, and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.



Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Mon Mar 20, 2017 5:45 am 
Veteran
User avatar

Joined: Fri Aug 17, 2012 8:33 am
Posts: 436
Completed: Brilliant Shadows, Perceptions of the Dead, The Phantom Icecream Truck
Projects: Embers of Magic, Pale Spectrum, Perceptions of the Dead
Organization: Ithaqua Labs
Twitter: @ithaqualabs
Tumblr: geckosart
Deviantart: sitaart
I'm trying to set it up so that the script chooses from a list of sound effects to play randomly.

So it appears to be choosing a sound to play, but instead of randoming the sound each time it just replays the same.
Upon inspecting lint, it says
"game/script.rpy:64 unable to evaluate filename u'chalkshort'" for each instance of chalkshort and chalklong

I'm fairly certain the randoming works if I add $import random before the sound instances, but that command stops the game from being able to create new save files.

Any thoughts?

For the record:
"am1" is setup as
renpy.music.register_channel("am1", "sfx", False, file_suffix=".ogg")

Code:

#This is placed before start of script
init python:
    import random

#this is placed just inside of script
label start:
#this is a chalk writing sfx that is 3 seconds + long
$ linenum2 = random.randint(0,5)
$ randomvoiceclips = ["sfx/chalk/chalk_long/chalk1", "sfx/chalk/chalk_long/chalk2", "sfx/chalk/chalk_long/chalk3", "sfx/chalk/chalk_long/chalk4", "sfx/chalk/chalk_long/chalk5", "sfx/chalk/chalk_long/chalk6",]
$ chalklong = randomvoiceclips[linenum2]

#this is a chalk sfx that is ~1 second long

$ linenum = random.randint(0,10)
$ randomvoiceclips = ["sfx/chalk/chalk_short/chalk1", "sfx/chalk/chalk_short/chalk2", "sfx/chalk/chalk_short/chalk3", "sfx/chalk/chalk_short/chalk4", "sfx/chalk/chalk_short/chalk5", "sfx/chalk/chalk_short/chalk6", "sfx/chalk/chalk_short/chalk7", "sfx/chalk/chalk_short/chalk8", "sfx/chalk/chalk_short/chalk9", "sfx/chalk/chalk_short/chalk10", "sfx/chalk/chalk_short/chalk11"]
$ chalkshort = randomvoiceclips[linenum]


play am1 chalkshort
"test test test chalk short"


play am1 chalklong
"plab plab blab chalk long"


_________________
Image ImageImage


Last edited by Geckos on Tue Mar 21, 2017 4:26 am, edited 3 times in total.

Top
 Profile Send private message  
 
PostPosted: Mon Mar 20, 2017 6:33 am 
Eileen-Class Veteran

Joined: Wed Dec 04, 2013 12:33 pm
Posts: 1109
Why random and not renpy.random?


Top
 Profile Send private message  
 
PostPosted: Mon Mar 20, 2017 6:50 am 
Eileen-Class Veteran
User avatar

Joined: Sat Feb 25, 2012 8:45 pm
Posts: 1009
Location: Italy
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Twitter: @xavimat_
Github: xavi-mat
Random is already imported inside renpy (with some adaptations to work with rollback) so you can use renpy.random,as philat suggests.

The code you have shown lacks "labels" so we can't see how the flow works.

This is my suggestion:
Code:
## outside any label:
default randomvoiceclips_long = ["sfx/chalk/chalk_long/chalk1", "sfx/chalk/chalk_long/chalk2", "sfx/chalk/chalk_long/chalk3", "sfx/chalk/chalk_long/chalk4", "sfx/chalk/chalk_long/chalk5", "sfx/chalk/chalk_long/chalk6",]

default randomvoiceclips_short = ["sfx/chalk/chalk_short/chalk1", "sfx/chalk/chalk_short/chalk2", "sfx/chalk/chalk_short/chalk3", "sfx/chalk/chalk_short/chalk4", "sfx/chalk/chalk_short/chalk5", "sfx/chalk/chalk_short/chalk6", "sfx/chalk/chalk_short/chalk7", "sfx/chalk/chalk_short/chalk8", "sfx/chalk/chalk_short/chalk9", "sfx/chalk/chalk_short/chalk10", "sfx/chalk/chalk_short/chalk11"]

# Inside your labels:
label some_label:
    play sound renpy.random.choice(randomvoiceclips_long)
    "Now a long sound is playing..."
    play sound renpy.random.choice(randomvoiceclips_short)
    "Now a short sound is playing..."

_________________
Cops&Robbers A two-player experiment
Fear&Love Why can’t we simply express our feelings? Why am I afraid to say ‘I love you’?
unknown [Sci-Fi - mystery - computer]
Honest Critique (Avatar made with Chibi Maker by ~gen8)


Top
 Profile Send private message  
 
PostPosted: Mon Mar 20, 2017 5:29 pm 
Veteran
User avatar

Joined: Fri Aug 17, 2012 8:33 am
Posts: 436
Completed: Brilliant Shadows, Perceptions of the Dead, The Phantom Icecream Truck
Projects: Embers of Magic, Pale Spectrum, Perceptions of the Dead
Organization: Ithaqua Labs
Twitter: @ithaqualabs
Tumblr: geckosart
Deviantart: sitaart
Using the other code does generate a random sound for each line that calls it, but lint still pulls up:

game/mountain.rpy:5033 unable to evaluate filename u'renpy.random.choice(randomvoiceclips_long)'


The reason why I was trying the initial code is because I would also like to use it to pick random lines+the same random voice lines to play. Is Renpy.random capable of this as well?

Code:

$linenum = random.randint(0,2)
$randomlines = ["Hello this is line 1","Hello this is line 2","Hello this is line 3"]
$randomvoiceclips = ["aku/chap4/aku01", "aku/chap4/aku02", "aku/chap4/aku03"]
$selectedline = randomlines[linenum]
$selectedvoice = randomvoiceclips[linenum]

play voice selectedvoice
aku "[selectedline]."


_________________
Image ImageImage


Top
 Profile Send private message  
 
PostPosted: Mon Mar 20, 2017 6:34 pm 
Veteran
User avatar

Joined: Mon Dec 14, 2015 5:05 am
Posts: 438
Location: Your monitor
Projects: Cooking with RWBY
Your files have no extension
Chalk3, for example is not a file but Chalk3.mp3 or Chslk3.ogg is a file

_________________
Need some free sound effects for your game?
viewtopic.php?f=48&t=42167
Cooking with RWBY


Top
 Profile Send private message  
 
PostPosted: Mon Mar 20, 2017 6:44 pm 
Lemma-Class Veteran
User avatar

Joined: Sun Sep 18, 2011 10:13 am
Posts: 2437
Files are playing so suffix is likely to be setup for the channel. Maybe:

Code:
## outside any label:
default randomvoiceclips_long = ["sfx/chalk/chalk_long/chalk1", "sfx/chalk/chalk_long/chalk2", "sfx/chalk/chalk_long/chalk3", "sfx/chalk/chalk_long/chalk4", "sfx/chalk/chalk_long/chalk5", "sfx/chalk/chalk_long/chalk6",]

default randomvoiceclips_short = ["sfx/chalk/chalk_short/chalk1", "sfx/chalk/chalk_short/chalk2", "sfx/chalk/chalk_short/chalk3", "sfx/chalk/chalk_short/chalk4", "sfx/chalk/chalk_short/chalk5", "sfx/chalk/chalk_short/chalk6", "sfx/chalk/chalk_short/chalk7", "sfx/chalk/chalk_short/chalk8", "sfx/chalk/chalk_short/chalk9", "sfx/chalk/chalk_short/chalk10", "sfx/chalk/chalk_short/chalk11"]

# Inside your labels:
label some_label:
    $ temp = renpy.random.choice(randomvoiceclips_long)
    play audio temp
    "Now a long sound is playing..."
    $ temp = renpy.random.choice(randomvoiceclips_short)
    play audio temp
    "Now a short sound is playing..."


will work? (code borrowed from xavimat's post)


Top
 Profile Send private message  
 
PostPosted: Tue Mar 21, 2017 12:04 am 
Veteran
User avatar

Joined: Fri Aug 17, 2012 8:33 am
Posts: 436
Completed: Brilliant Shadows, Perceptions of the Dead, The Phantom Icecream Truck
Projects: Embers of Magic, Pale Spectrum, Perceptions of the Dead
Organization: Ithaqua Labs
Twitter: @ithaqualabs
Tumblr: geckosart
Deviantart: sitaart
Imperf3kt wrote:
Your files have no extension
Chalk3, for example is not a file but Chalk3.mp3 or Chslk3.ogg is a file


I have my sound channels set up to do that for me automatically, sorry for any confusion there!

Giving the latest code a whirl!

_________________
Image ImageImage


Top
 Profile Send private message  
 
PostPosted: Tue Mar 21, 2017 2:51 am 
Veteran
User avatar

Joined: Thu May 31, 2012 11:17 pm
Posts: 492
Completed: a2 ~a due~
Projects: AXIOM.01, The Pirate Mermaid
Organization: Variable X, Navigame
Twitter: @arowana_vx
Tumblr: navigame-media
itch.io: navigame
EDIT: Sorry, I think I misunderstood the problem the first time. If this isn't relevant, please skip to my post after this. :lol:

***

FYI, renpy.random participates in rollback, so you'll generate the same result regardless of how many times you roll back (see documentation here). If you want the result to change each time, you'll need random instead of renpy.random, which is actually what you had in your first post.

I actually think the code in your first post looks mostly okay (assuming that everything was indented properly), but there is an extra comma in one of the lists.
Quote:
$ randomvoiceclips = ["sfx/chalk/chalk_long/chalk1", "sfx/chalk/chalk_long/chalk2", "sfx/chalk/chalk_long/chalk3", "sfx/chalk/chalk_long/chalk4", "sfx/chalk/chalk_long/chalk5", "sfx/chalk/chalk_long/chalk6",] #####<------ extra comma at the end here

Try removing that comma and see if that helps? Or if you want to use xela's code, you could do:
Quote:
## outside any label:
default randomvoiceclips_long = ["sfx/chalk/chalk_long/chalk1", "sfx/chalk/chalk_long/chalk2", "sfx/chalk/chalk_long/chalk3", "sfx/chalk/chalk_long/chalk4", "sfx/chalk/chalk_long/chalk5", "sfx/chalk/chalk_long/chalk6",]

default randomvoiceclips_short = ["sfx/chalk/chalk_short/chalk1", "sfx/chalk/chalk_short/chalk2", "sfx/chalk/chalk_short/chalk3", "sfx/chalk/chalk_short/chalk4", "sfx/chalk/chalk_short/chalk5", "sfx/chalk/chalk_short/chalk6", "sfx/chalk/chalk_short/chalk7", "sfx/chalk/chalk_short/chalk8", "sfx/chalk/chalk_short/chalk9", "sfx/chalk/chalk_short/chalk10", "sfx/chalk/chalk_short/chalk11"]

init python: #<----- add this like in your first post
import random

# Inside your labels:
label some_label:
$ temp = random.choice(randomvoiceclips_long) #<---- change renpy.random to random
play audio temp
"Now a long sound is playing..."
$ temp = random.choice(randomvoiceclips_short) #<---- change renpy.random to random
play audio temp
"Now a short sound is playing..."

_________________
Complete: a2 ~a due~ (music, language, love)
In progress: The Pirate Mermaid (fairytale otome)
On hold: AXIOM.01 (girl detective game)

Image


Last edited by Arowana on Tue Mar 21, 2017 4:08 am, edited 1 time in total.

Top
 Profile Send private message  
 
PostPosted: Tue Mar 21, 2017 2:58 am 
Eileen-Class Veteran

Joined: Wed Dec 04, 2013 12:33 pm
Posts: 1109
Why would you want the sound to change each time you rollback? You'd want the sound to change each time you want to play a new sound, yes. But why on rollback?


Top
 Profile Send private message  
 
PostPosted: Tue Mar 21, 2017 3:03 am 
Veteran
User avatar

Joined: Thu May 31, 2012 11:17 pm
Posts: 492
Completed: a2 ~a due~
Projects: AXIOM.01, The Pirate Mermaid
Organization: Variable X, Navigame
Twitter: @arowana_vx
Tumblr: navigame-media
itch.io: navigame
philat wrote:
Why would you want the sound to change each time you rollback? You'd want the sound to change each time you want to play a new sound, yes. But why on rollback?

I'm not sure why in this case. But that's what Geckos requested, if I understand them correctly? :lol:

EDIT: Ah okay, I think I misunderstood after all, sorry. :oops: The problem was not that the sounds aren't randomized correctly, but rather that Lint is giving errors for chalkshort and chalklong (or whichever stand-in for the filename you are using)?

Maybe the play statement is having trouble with the stand-in filename. Have you tried the equivalent renpy function instead? So, for example, in place of a play statement like this:
Code:
play am1 chalkshort

Use:
Code:
$renpy.music.play(chalkshort, channel="am1")


Similarly, for xela's example:
Code:
play audio temp

would become:
Code:
$renpy.music.play(temp, channel="audio")


I gave this a try and didn't get any Lint errors, so I hope it works for you. :D

_________________
Complete: a2 ~a due~ (music, language, love)
In progress: The Pirate Mermaid (fairytale otome)
On hold: AXIOM.01 (girl detective game)

Image


Top
 Profile Send private message  
 
PostPosted: Tue Mar 21, 2017 4:23 am 
Veteran
User avatar

Joined: Fri Aug 17, 2012 8:33 am
Posts: 436
Completed: Brilliant Shadows, Perceptions of the Dead, The Phantom Icecream Truck
Projects: Embers of Magic, Pale Spectrum, Perceptions of the Dead
Organization: Ithaqua Labs
Twitter: @ithaqualabs
Tumblr: geckosart
Deviantart: sitaart
Alright!
I apologize for bringing a question that was more like 2 or 3 questions here, that was sloppy of me, and me just biting off more than I could chew as usual.

That being said, I was able to remedy the randoming sound effect to my liking.
So it plays a random sound effect for every instance of it being called, instead of just picking one sound effect and replaying it over and over again.

I achieved this (or Caelem did, who helped me!) by doing this:

Code:
init python:
    import random
   

    def chalklong():
            linenum2 = random.randint(0,5)
            randomvoiceclips = ["sfx/chalk/chalk_long/chalk1", "sfx/chalk/chalk_long/chalk2", "sfx/chalk/chalk_long/chalk3", "sfx/chalk/chalk_long/chalk4", "sfx/chalk/chalk_long/chalk5", "sfx/chalk/chalk_long/chalk6",]
            chalk = randomvoiceclips[linenum2]
            return chalk

    def chalkshort():
            linenum = random.randint(0,10)
            randomvoiceclips = ["sfx/chalk/chalk_short/chalk1", "sfx/chalk/chalk_short/chalk2", "sfx/chalk/chalk_short/chalk3", "sfx/chalk/chalk_short/chalk4", "sfx/chalk/chalk_short/chalk5", "sfx/chalk/chalk_short/chalk6", "sfx/chalk/chalk_short/chalk7", "sfx/chalk/chalk_short/chalk8", "sfx/chalk/chalk_short/chalk9", "sfx/chalk/chalk_short/chalk10", "sfx/chalk/chalk_short/chalk11"]
            chalk = randomvoiceclips[linenum]
            return chalk   

label start:   

play am1 chalkshort()
speaker "This plays a short chalk sound!"
play am1 chalklong()
speaker "this plays a long chalk sound!"





That aside, using the code that Arowana suggested,
$renpy.music.play(selectedvoice, channel="voice")
Lint is no longer angry at me (yay!), and I can use the code below to say a random line from a list, as well as play the same, random voiced line at the same time!

It's everything silly I can now do in ren'py and more.


Code:

$linenum = random.randint(0,2)
$randomlines = ["Hello this is line 1","Here kitty, kitty!","Uh..."]
$randomvoiceclips = ["aku/chap4/aku01", "aku/chap4/aku02", "aku/chap4/aku03"]
$selectedline = randomlines[linenum]
$selectedvoice = randomvoiceclips[linenum]

$renpy.music.play(selectedvoice, channel="voice")
speaker "[selectedline]."



That is all of my problems fixed, and you are all awesome and thank you for letting me pick your brains.

P.s.
Would it be better to use
play voice selectedvoice
aku "[selectedline]."

To play the random clips as opposed to $renpy.music.play(selectedvoice, channel="voice")?
Lint complained with

game/script.rpy:121 unable to evaluate filename u'selectedvoice'

But there were otherwise no apparent errors from using

play voice selectedvoice
aku "[selectedline]."

instead of

$renpy.music.play(selectedvoice, channel="voice")
aku "[selectedline]."

_________________
Image ImageImage


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Donmai


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Protected by Anti-Spam ACP
Powered by phpBB® Forum Software © phpBB Group