View unanswered posts | View active topics It is currently Tue Aug 21, 2018 6:20 pm



Reply to topic  [ 3 posts ] 
 Another poor attempt at scripting. 
Author Message
User avatar

Joined: Mon Oct 25, 2010 5:51 am
Posts: 1197
Location: Sydney
Reply with quote
Post 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 :roll:

Anyone, please ;___;


Mon Jun 25, 2012 11:14 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post 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


Mon Jun 25, 2012 2:37 pm
Profile
User avatar

Joined: Mon Oct 25, 2010 5:51 am
Posts: 1197
Location: Sydney
Reply with quote
Post 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 :)


Mon Jun 25, 2012 3:33 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.016s | 15 Queries | GZIP : Off ]