Data Realms Fan Forums
http://45.55.195.193/

Why won't this script work?
http://45.55.195.193/viewtopic.php?f=73&t=31594
Page 1 of 1

Author:  OmegaX17 [ Sat Aug 18, 2012 2:30 am ]
Post subject:  Why won't this script work?

Ok, I've tried this every way now, and this is the latest.
I'm trying to make a script that makes the gun overheat after firing too long.
Every time I test it out, the gun just ignores the file. The game starts, I can use the gun, but it won't overheat.

Code:
function Create(self)
  self.ShootTimer = Timer()
  self.Heat = Timer()
  self.Cooling = 2
end
function Update(self)
  if self:IsActivated() then
    if self.ShootTimer:IsPastSimMS(60000/self.RateOfFire) then
      self.ShootTimer:Reset()
      if self.ShootTimer > 0 then
        self.Heat = self.Heat + 1
      if self.Heat <= 50 then
        self.Heat = self.Heat - self.Cooling*2
      if self.Heat >= 50 then
        self.Heat = self.Heat - self.Cooling
      if self.Heat >= 100 then
        self.disable
        self.RateOfFire = 10
      end
    end
  end
end

Author:  Asklar [ Sat Aug 18, 2012 2:35 am ]
Post subject:  Re: Why won't this script work?

The first thing you do on the if clause is resetting the timer, when it should be the last thing. If you do it at the beggining, the condition for the if won't be met, and it'll start over without doing anything.

And I'm not sure self.disable does anything at all.

Author:  OmegaX17 [ Sat Aug 18, 2012 3:03 am ]
Post subject:  Re: Why won't this script work?

Asklar wrote:
The first thing you do on the if clause is resetting the timer, when it should be the last thing. If you do it at the beggining, the condition for the if won't be met, and it'll start over without doing anything.

And I'm not sure self.disable does anything at all.


I'll edit it in a bit, thank you. Also, if self.disable doesnt work, do you know a function that disables the weapon?
EDIT: setting rate of fire to 0 until heat is down should work fine

Author:  Asklar [ Sat Aug 18, 2012 3:05 am ]
Post subject:  Re: Why won't this script work?

Or self:Deactivate().

Author:  OmegaX17 [ Sat Aug 18, 2012 8:16 pm ]
Post subject:  Re: Why won't this script work?

Asklar wrote:
Or self:Deactivate().

Crap, I knew disable wasnt it, thanks again :D

Tested it, script still won't work.
Current script
Code:
function Create(self)
  self.ShootTimer = Timer()
  self.Heat = Timer()
  self.Cooling = 2
end
function Update(self)
  if self:IsActivated() then
    if self.ShootTimer:IsPastSimMS(60000/self.RateOfFire) then
      if self.ShootTimer > 0 then
        self.Heat = self.Heat + 2
      if self.Heat <= 0 then
         self.Activate
         self.RateOfFire = 1200
      if self.Heat <= 6 then
        self.RateOfFire = 200
      if self.Heat <= 50 then
        self.RateOfFire = 1200
        self.Heat = self.Heat - self.Cooling*2
      if self.Heat >= 50 then
        self.Heat = self.Heat - self.Cooling
        self.RateOfFire = 1200
      if self.Heat <= 90 then
        self.RateOfFire = 600
      else
        self.RateOfFire = 1200
      if self.Heat >= 90 then
        self. RateOfFire = 200
      else
        self.RateOfFire = 1200
      if self.Heat >= 100 then
        self.Deactivate()
      else
        self.RateOfFire = 1200
      self.ShootTimer:Reset()
      end
    end
  end
end

Author:  OmegaX17 [ Sat Aug 18, 2012 8:31 pm ]
Post subject:  Re: Why won't this script work?

Nonsequitorian wrote:
That's a really badly written script. Not the content, it's just you have about a billion if statements that aren't closed. Every if has to be met with an end somewhere.


Oh, jeez :/
Thank you, gonna go do that right now.
EDIT: Hmm, still seems to not work, does the end go like this
Code:
if self.Heat >= 100 then
 self.Deactivate()
else
 self.RateOfFire = 1200
end

Or
Code:
if self.Heat >= 100 then
  self.Deactivate()
end
else
  self.RateOfFire = 1200

Author:  OmegaX17 [ Sat Aug 18, 2012 8:39 pm ]
Post subject:  Re: Why won't this script work?

Nonsequitorian wrote:
the former.

if bla then
bluh
else
blagh
end

But you could get rid of all that and have a script that instead is a formula, something like


self.RateOfFire = 100/self.Heat

I don't know exactly what you want with the speed, but you could do that much easier and get a less cluttered script


I didnt think of that :oops: That'd work great, thank you. :grin:

Author:  Bad Boy [ Sat Aug 18, 2012 10:27 pm ]
Post subject:  Re: Why won't this script work?

Also, unless I'm mistaken you can't check if a timer is > something, try
if self.shoottimer:IsPastSimMS(100) then...

And as was said your script needs cleanup, I'd be very surprised if you don't have a console full of errors. But keep trying, it's the only way to learn :)

Author:  OmegaX17 [ Sun Aug 19, 2012 3:03 am ]
Post subject:  Re: Why won't this script work?

Bad Boy wrote:
Also, unless I'm mistaken you can't check if a timer is > something, try
if self.shoottimer:IsPastSimMS(100) then...

And as was said your script needs cleanup, I'd be very surprised if you don't have a console full of errors. But keep trying, it's the only way to learn :)


3rd day of Lua coding, pretty much the only thing I CAN do is learn, from my many mistakes :grin:

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/