Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help,
read this .
Joliplex
Prole
Posts: 7 Joined: Wed Dec 07, 2011 12:17 pm
Post
by Joliplex » Sat Dec 10, 2011 11:13 am
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!
dar0n123
Prole
Posts: 7 Joined: Fri Nov 25, 2011 6:10 pm
Post
by dar0n123 » Sat Dec 10, 2011 12:48 pm
+
Last edited by
dar0n123 on Thu Oct 30, 2014 4:38 pm, edited 1 time in total.
bartbes
Sex machine
Posts: 4946 Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:
Post
by bartbes » Sat Dec 10, 2011 1:16 pm
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)
Joliplex
Prole
Posts: 7 Joined: Wed Dec 07, 2011 12:17 pm
Post
by Joliplex » Sat Dec 10, 2011 1:38 pm
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
Metalcookie
Prole
Posts: 16 Joined: Sat Dec 10, 2011 2:57 pm
Location: Netherlands
Post
by Metalcookie » Sat Dec 10, 2011 4:43 pm
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.
kikito
Inner party member
Posts: 3153 Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:
Post
by kikito » Sat Dec 10, 2011 5:27 pm
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.
When I write def I mean function .
bartbes
Sex machine
Posts: 4946 Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:
Post
by bartbes » Sat Dec 10, 2011 6:06 pm
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.
Taehl
Dreaming in associative arrays
Posts: 1025 Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:
Post
by Taehl » Sat Dec 10, 2011 7:43 pm
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
Last edited by
Taehl on Sat Dec 10, 2011 7:56 pm, edited 1 time in total.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet , built like a tank . But not fancy enough for Love2D 0.10.0+.
bartbes
Sex machine
Posts: 4946 Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:
Post
by bartbes » Sat Dec 10, 2011 7:54 pm
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.
kikito
Inner party member
Posts: 3153 Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:
Post
by kikito » Sun Dec 11, 2011 1:11 am
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
When I write def I mean function .
Users browsing this forum: Bing [Bot] and 1 guest