|
Page 1 of 1
|
[ 9 posts ] |
|
Why won't this script work?
Author |
Message |
OmegaX17
Joined: Mon Dec 26, 2011 9:52 pm Posts: 78
|
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
|
Sat Aug 18, 2012 2:30 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
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.
|
Sat Aug 18, 2012 2:35 am |
|
|
OmegaX17
Joined: Mon Dec 26, 2011 9:52 pm Posts: 78
|
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
|
Sat Aug 18, 2012 3:03 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Why won't this script work?
Or self:Deactivate().
|
Sat Aug 18, 2012 3:05 am |
|
|
OmegaX17
Joined: Mon Dec 26, 2011 9:52 pm Posts: 78
|
Re: Why won't this script work?
Asklar wrote: Or self:Deactivate(). Crap, I knew disable wasnt it, thanks again 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
|
Sat Aug 18, 2012 8:16 pm |
|
|
OmegaX17
Joined: Mon Dec 26, 2011 9:52 pm Posts: 78
|
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
|
Sat Aug 18, 2012 8:31 pm |
|
|
OmegaX17
Joined: Mon Dec 26, 2011 9:52 pm Posts: 78
|
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 That'd work great, thank you.
|
Sat Aug 18, 2012 8:39 pm |
|
|
Bad Boy
Joined: Fri Sep 10, 2010 1:48 am Posts: 666 Location: Halifax, Canada
|
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
|
Sat Aug 18, 2012 10:27 pm |
|
|
OmegaX17
Joined: Mon Dec 26, 2011 9:52 pm Posts: 78
|
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
|
Sun Aug 19, 2012 3:03 am |
|
|
|
|
Page 1 of 1
|
[ 9 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
|
|