Kraxie Posted April 9, 2015 Share Posted April 9, 2015 Hai! I have a function for changing the music track in my game and it works fine and all, but I also want it to get the total length of the track... Here is my function I'm currently using: function App:SwitchMusic(name) App.source:Stop() local sound = Sound:Load("Sound/BGM/" .. name .. ".wav") App.source:SetSound(sound) App.source:Play() end I tried adding something like App.tracklength = Math:Round(self.name:GetLength()) But it only returns in an error, since I guess it's trying to find a loaded sound with the name "name" and not from the variable. Do anyone have any idea how I can solve this? Thanks! KraXarN Quote Windows 7 | Intel Core i7-4790K | 16 GB RAM | Nvidia GTX 980 Link to comment Share on other sites More sharing options...
Rick Posted April 9, 2015 Share Posted April 9, 2015 What is self.name? So your sound variable has the GetLength() function. So after you load the sound store that in another variable. local sound = Sound:Load() self.soundLength = sound:GetLength() self.source:SetSound(sound) sound:Release() self.source:Play() If you are inside App functions than you can use self vs App. They mean the same thing because you are in the App "class" but it's general practice to use self vs the table name itself. Quote Link to comment Share on other sites More sharing options...
Kraxie Posted April 9, 2015 Author Share Posted April 9, 2015 Exactly what I was looking for! Thanks! I don't really know why I used App there instead of self, but changed it and all works fine now so... EDIT: I found out that it works just fine, but when drawing it, it works for a little while until the game freezes and just randomly closes... Quote Windows 7 | Intel Core i7-4790K | 16 GB RAM | Nvidia GTX 980 Link to comment Share on other sites More sharing options...
Rick Posted April 9, 2015 Share Posted April 9, 2015 What are you drawing? These are sounds.. Show that code. Quote Link to comment Share on other sites More sharing options...
Kraxie Posted April 9, 2015 Author Share Posted April 9, 2015 I recreated the game .exe file and now it works... so nevermind... Quote Windows 7 | Intel Core i7-4790K | 16 GB RAM | Nvidia GTX 980 Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.