From 0ace40cf66b01c127eab363c392a54c5fd4a18ff Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Mon, 24 Oct 2011 19:43:47 +0200 Subject: [PATCH] Fix instance setter, Add ability to chose one sound at random --- bdsm/bdsm.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bdsm/bdsm.lua b/bdsm/bdsm.lua index de6c4ee..96c81b8 100644 --- a/bdsm/bdsm.lua +++ b/bdsm/bdsm.lua @@ -44,10 +44,17 @@ local function remove_stopped(sources) end end +local function get_what(what) + if type(what) == 'table' then + return what[math.random(1,#what)] + end + return what +end + local play_instance, stop_instance function Source:play() remove_stopped(self.instances) - local instance = newInstance(self.what, self.how) + local instance = newInstance(get_what(self.what), self.how) -- overwrite instance:stop() and instance:play() if not (play_instance and stop_instance) then @@ -103,7 +110,7 @@ for _, property in ipairs{'looping', 'pitch', 'volume'} do Source['set' .. name] = function(self, val) self[property] = val for s in pairs(self.instances) do - s['set' .. name](self, val) + s['set' .. name](s, val) end end end