• A little help here?
    15 replies, posted
Yeah.. I finished making something for the composer of super meat boy but it's got a bug.. What it's supposed to do is play a different song whenever you press mouse 2... The song changing works, sort of.. The song value changes, but the song that plays does not. [url]http://pastebin.com/Kbafp2k3[/url] Anyone offer any advice or post a fix? I've been trying to fix this for weeks with no progress. All help would be appreciated.
Anyone?
You would need to constantly read dsong to see when it has changed or you could hook it to stop the sound the sweps currently at and play the new song. When you switch the song nothing make the new song play.
[QUOTE=zzaacckk;26730447]You would need to constantly read dsong to see when it has changed or you could hook it to stop the sound the sweps currently at and play the new song. When you switch the song nothing make the new song play.[/QUOTE] I know that. But i dont know how to fix that D: I'm new to coding.
Try stopping the song before starting a new one.
Okay... I'll just attach a stop sound to the secondary attack... Now... a little help on that?
Hello?
SWEP:SecondaryAttack()?
Another question.. How would i set it up to where it constantly reads dsong so i can get the song to change properly?
[lua] local dsong = math.random(1,5) function switchsong() if dsong == 1 then dsong = 2 SWEP.Sound = Sound ("smbgarry1.wav") elseif dsong == 2 then dsong = 3 SWEP.Sound = Sound ("smbgarry2.wav") elseif dsong == 3 then dsong = 4 SWEP.Sound = Sound ("smbgarry3.wav") elseif dsong == 4 then dsong = 5 SWEP.Sound = Sound ("smbgarry4.wav") else dsong = 1 SWEP.Sound = Sound ("smbgarry5.wav") end end [/lua] Its painful to look at your code, afaik "else if" doesn't work, use "elseif" [lua] function Identifysong() if dsong == 1 then for _, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "Song Title: The Battle of Lil' Slugger (Ch 1 Boss)") end elseif dsong == 2 then for _, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "Song Title: C.H.A.D.'s Lullaby (Ch 2 Boss)") end elseif dsong == 3 then for _, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "Song Title: Betus Blues (Ch 2 Light World)") end elseif dsong == 4 then for _, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "Song Title: Hot Damned (Ch 4 Light World)") end elseif dsong == 5 then for _, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "Song Title: Carmeaty Burana (Ch 6 Boss)") end end end[/lua] You could just mix those and save a few lines.
[QUOTE=Zephilinox;26861031][lua] local dsong = math.random(1,5) function switchsong() if dsong == 1 then dsong = 2 SWEP.Sound = Sound ("smbgarry1.wav") elseif dsong == 2 then dsong = 3 SWEP.Sound = Sound ("smbgarry2.wav") elseif dsong == 3 then dsong = 4 SWEP.Sound = Sound ("smbgarry3.wav") elseif dsong == 4 then dsong = 5 SWEP.Sound = Sound ("smbgarry4.wav") else dsong = 1 SWEP.Sound = Sound ("smbgarry5.wav") end end [/lua] Its painful to look at your code, afaik "else if" doesn't work, use "elseif" [lua] function Identifysong() if dsong == 1 then for _, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "Song Title: The Battle of Lil' Slugger (Ch 1 Boss)") end elseif dsong == 2 then for _, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "Song Title: C.H.A.D.'s Lullaby (Ch 2 Boss)") end elseif dsong == 3 then for _, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "Song Title: Betus Blues (Ch 2 Light World)") end elseif dsong == 4 then for _, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "Song Title: Hot Damned (Ch 4 Light World)") end elseif dsong == 5 then for _, v in pairs(player.GetAll()) do v:PrintMessage( HUD_PRINTCENTER, "Song Title: Carmeaty Burana (Ch 6 Boss)") end end end[/lua] You could just mix those and save a few lines.[/QUOTE] Painful to look at my code.. Maybe.. Am i new to coding? Definitely.
If it's painful to look at your code people will be less inclined to help you. If you want help with this, other people need to be able to read it easily - proper formatting and indentation help this massively.
I suppose i can work on cleaning it up.. But theres a reason for the functions not being combined.
instead of doing for use the for loop like 10 times just do this: [lua]function Identifysong() for _, v in pairs(player.GetAll()) do if dsong == 1 then v:PrintMessage( HUD_PRINTCENTER, "Song Title: The Battle of Lil' Slugger (Ch 1 Boss)") elseif dsong == 2 then v:PrintMessage( HUD_PRINTCENTER, "Song Title: C.H.A.D.'s Lullaby (Ch 2 Boss)") elseif dsong == 3 then v:PrintMessage( HUD_PRINTCENTER, "Song Title: Betus Blues (Ch 2 Light World)") elseif dsong == 4 then v:PrintMessage( HUD_PRINTCENTER, "Song Title: Hot Damned (Ch 4 Light World)") elseif dsong == 5 then v:PrintMessage( HUD_PRINTCENTER, "Song Title: Carmeaty Burana (Ch 6 Boss)") end end end[/lua] [editline]24th December 2010[/editline] also :wtc: is with your tabbing here [img]http://gyazo.com/c3350802bcd0bd8333a97da3d9718bc9.png[/img]
[lua] local stab = {"The Battle of Lil' Slugger (Ch 1 Boss)", "C.H.A.D.'s Lullaby (Ch 2 Boss)", "Betus Blues (Ch 2 Light World)"}; local dsong = 2; function Identifysong() local song = stab[dsong] || ''; PrintMessage(HUD_PRINTCENTER, 'Song Title: '..song); end [/lua]
I don't want to be an ass but the code was a bit messy in my opinion so I started from scratch. This might not be what you've asked for but I hope it will help. The swep is tested and it works (at least in sp). This swep will automatically load all the music in the directory you specify. If it can't find any music in that directory it will load music from some games such as hl2, hl2 ep1, hl2 ep2, portal (not tf2, sorry). The swep will start at a random song. Cycle through your music list with primary and secondary fire. Stop song with reload. I've left the ShowCurrentSong function empty so you can implement it any way you like. [lua] SWEP.dir = "../sound/swepMusic/" SWEP.filetype = ".mp3" SWEP.musicNames = {} SWEP.music = {} SWEP.nrOfMusic = 0 SWEP.musicNr = 1 SWEP.Stopped = false SWEP.SwitchSongDel = CurTime() SWEP.SwitchSongDelAddDelay = 0.5 function SWEP:Initialize() --Get all the mp3 files from the directory local mp3Files = file.Find( self.dir.."*"..self.filetype ) --Inserting them in the music names table for _, plugin in ipairs( mp3Files ) do table.insert( self.musicNames, plugin ) end --If we can't find any music we will load all the music from all source games if table.Count( self.musicNames ) <= 0 then self.dir = "../sound/music/" mp3Files = file.Find( self.dir.."*.mp3" ) for _, plugin in ipairs( mp3Files ) do table.insert( self.musicNames, plugin ) end end --Creating all the sounds for i, plugin in ipairs( self.musicNames ) do self.music[i] = CreateSound(self, self.dir..self.musicNames[i]) end --Getting the number of sounds and setting a random music track self.nrOfMusic = table.Count( self.musicNames ) self.musicNr = math.random( 1, self.nrOfMusic ) end --Play current song function SWEP:Deploy() self:PlaySong( 0 ) end --Select next song function SWEP:PrimaryAttack() self:PlaySong( 1 ) end --Select previous song function SWEP:SecondaryAttack() self:PlaySong( -1 ) end --Stop the song when holstering function SWEP:Holster( wep ) self.music[self.musicNr]:Stop() return true end --Stop the music --The swep will start play the same track we stopped since we set self.Stopped to true function SWEP:Reload() self.Stopped = true self.music[self.musicNr]:Stop() end function SWEP:ShowCurrentSong( songName ) --You should complement this function! end function SWEP:PlaySong( cycle ) if self.SwitchSongDel < CurTime() then self.SwitchSongDel = CurTime() + self.SwitchSongDelAddDelay --Stop the music currently playing self.music[self.musicNr]:Stop() --If the music was stopped (by pressing reload) we will plat the same song if self.Stopped == false then self.musicNr = self.musicNr + cycle end self.Stopped = false --Could have used math.clamp() here. if self.musicNr <= 0 then self.musicNr = self.nrOfMusic end --and here if self.musicNr > self.nrOfMusic then self.musicNr = 1 end --Play the new song self.music[self.musicNr]:Play() self:ShowCurrentSong( self.musicNames[self.musicNr] ) end end [/lua]
Sorry, you need to Log In to post a reply to this thread.