Data Realms Fan Forums http://45.55.195.193/ |
|
Another poor attempt at scripting. http://45.55.195.193/viewtopic.php?f=73&t=31339 |
Page 1 of 1 |
Author: | Kettenkrad [ Mon Jun 25, 2012 11:14 am ] |
Post subject: | Another poor attempt at scripting. |
I'll get right into it: So I'm trying to have a weapon choose a random firing sound from a list when it's created, and stick with that firing sound until it's destroyed. Code: function Create(self) ... self.FireSounds = {(CreateAEmitter("Dispenser.rte/Fire Sound 1")) , (CreateAEmitter("Dispenser.rte/Fire Sound 2")) , etc..}; local Sound = (self.FireSounds[math.random(1,4)]); self.SoundTimer = Timer(); ... end Is where it should get the sounds from, and Code: function Update(self) ... -- Fire Sounds: if self:IsActivated() and self.Magazine then if self.SoundTimer:IsPastSimMS(60000/self.ROF) then self.SoundTimer:Reset(); Sound.Pos = self.Pos; MovableMan:AddParticle(Sound); end end ... end uses a bit of Akblabla's script to have it add the sound particle every time the weapon fires. My problem is that when I define 'Sound' as a local variable in Create, the Update function cannot find it. Whenever I define it as 'self.Sound' in either function, the game glitches out, plays the sound once, and crashes shortly after. If I attempt to define 'Sound' in Update, as it's a math.random, I get a different sound every time, and the occasional crash Anyone, please ;___; |
Author: | Roast Veg [ Mon Jun 25, 2012 2:37 pm ] |
Post subject: | Re: Another poor attempt at scripting. |
The problem is you're trying to add the exact same AEmitter every frame, not a different one. Try: Code: function Create(self) ... self.FireSounds = {"Dispenser.rte/Fire Sound 1" , "Dispenser.rte/Fire Sound 2", "Dispenser.rte/Fire Sound 3", "Dispenser.rte/Fire Sound 4"}; --Define the locations as strings, not particles. self.SoundPath = (self.FireSounds[math.random(1,4)]); --Just the one string. self.SoundTimer = Timer(); ... end function Update(self) ... -- Fire Sounds: if self:IsActivated() and self.Magazine then if self.SoundTimer:IsPastSimMS(60000/self.ROF) then local Sound = CreateAEmitter(self.SoundPath) --NOW it's a local AEmitter. self.SoundTimer:Reset(); Sound.Pos = self.Pos; MovableMan:AddParticle(Sound); end end ... end |
Author: | Kettenkrad [ Mon Jun 25, 2012 3:33 pm ] |
Post subject: | Re: Another poor attempt at scripting. |
Roast Veg wrote: The problem is you're trying to add the exact same AEmitter every frame, not a different one. Try: Works perfectly, thanks a bunch, Roast |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |