Page 1 of 2
How to choose source?
Posted: Sat Dec 10, 2011 11:13 am
by Joliplex
Hi all!
I was thinking about ranom music. I tried at least these:
Code: Select all
source = love.audio.newSource("music1.mp3" or "music2.mp3" or "music3.mp3")
Code: Select all
source = love.audio.newSource(choose("music1.mp3", "music2.mp3", "music3.mp3"))
Code: Select all
source = love.audio.newSource(math.random("music1.mp3", "music2.mp3", "music3.mp3"))
I just can't figure it out! So if you can help, it will be super!
Thanks!
![Ultrahappy :ultrahappy:](./images/smilies/ms-ultrahappy.png)
Re: How to choose source?
Posted: Sat Dec 10, 2011 12:48 pm
by dar0n123
+
Re: How to choose source?
Posted: Sat Dec 10, 2011 1:16 pm
by bartbes
Something along the lines of:
Code: Select all
local music = {"music1.mp3", "music2.mp3", "music3.mp3"}
local song = music[math.random(1, #music)]
source = love.audio.newSource(song)
Re: How to choose source?
Posted: Sat Dec 10, 2011 1:38 pm
by Joliplex
Thaaank you! This will help me alot!
EDIT: It doesn't work! Can someone take a look at it?
I used mp3 files for testing, so it's... Big just now.
Here (cannot attach it):
http://www.mediafire.com/?du7u9n2w2i02p2b
Re: How to choose source?
Posted: Sat Dec 10, 2011 4:43 pm
by Metalcookie
I poked your code a bit and.. math.random() ain't random at all for your program, even after using math.randomseed(os.time())..
Sorry, but that's all I can do for now, good luck.
Re: How to choose source?
Posted: Sat Dec 10, 2011 5:27 pm
by kikito
Metalcookie wrote:I poked your code a bit and.. math.random() ain't random at all for your program, even after using math.randomseed(os.time())..
Sorry, but that's all I can do for now, good luck.
On the contrary, adding math.randomseed(os.time()) seemed to just do the trick for me...
Joliplex, try adding that line to your program, like this:
Code: Select all
function love.load() --Load stuff!
math.randomseed(os.time())
local source = {"Platform.mp3", "Push.mp3", "Prog_House.mp3"}
local song = source[math.random(1, #source)]
...
I tried it in my computer and it worked - the song was selected randomly every time I opened the game.
Re: How to choose source?
Posted: Sat Dec 10, 2011 6:06 pm
by bartbes
It has been reported many times that this is not sufficient for everyone, but generally, calling math.random() twice after math.randomseed() gives pretty good results.
Re: How to choose source?
Posted: Sat Dec 10, 2011 7:43 pm
by Taehl
Code: Select all
love.load()
require"TEsound"
math.randomseed(os.time()) math.random() math.random()
TEsound.playLooping( {"music1.mp3", "music2.mp3", "music3.mp3"} )
end
love.update(dt)
TEsound.cleanup()
end
![Awww :3](./images/smilies/ms-three.png)
Re: How to choose source?
Posted: Sat Dec 10, 2011 7:54 pm
by bartbes
Disregarding your non-working source, I am left with the impression that you try to plug your library, which seems to happen a bit often, especially considering there already was a solution here.
Re: How to choose source?
Posted: Sun Dec 11, 2011 1:11 am
by kikito
Independently of that, maybe we could "patch" randomseed to fix the occasional initial non-randomness?
I mean doing something like this directly in LÖVE:
Code: Select all
local prevseed = math.randomseed
math.randomseed = function(seed)
prevseed(seed)
for 1,10 math.random() end
end