Author |
Message |
Foogooman
Joined: Sat Nov 18, 2006 8:11 pm Posts: 267
|
I need help with this script real quick, small script.
Hey, so I have this weapon the "C4 Shotgun" I set it up so that it can be detonated by pressing Z and also by using a detonator, but the detonator only works sometimes and I'm not sure why. 80 percent of the time it doesn't blow up the C4. Here's the code Code: function Create(self) end
function Update(self) if (UInputMan:KeyHeld(26)) then self:GibThis(); print("C4 Spray planted!"); --Make sure the C-4 Spray list exists. if c4ListS == nil then --If not, create it. c4ListS = { }; end --Add this C-4 to the list. c4ListS[#c4ListS + 1] = self; end
end
And the code the detonator itself uses, but I don't think this is the problem Code: function Create(self) print("C4 Spray detonated!"); --Make sure the C-4 Spray list exists. if c4ListS ~= nil then --Go through the list of C-4 Spray. for i=1,#c4ListS do --Make sure the C-4 still exists, it may have been destroyed. if MovableMan:IsParticle(c4ListS[i]) then --Detonate the C-4! c4ListS[i]:GibThis(); end end end --Empty/create the red C-4 list. c4ListS = { }; end
|
Wed Jun 24, 2009 10:51 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: I need help with this script real quick, small script.
if not C4ListS then c4ListS = { }; else c4ListS[#c4ListS + 1] = self; end
|
Wed Jun 24, 2009 11:04 pm |
|
|
Foogooman
Joined: Sat Nov 18, 2006 8:11 pm Posts: 267
|
Re: I need help with this script real quick, small script.
Grif wrote: if not C4ListS then c4ListS = { }; else c4ListS[#c4ListS + 1] = self; end What do I do with that? D: I don't know Lua at all, just some common sense.
|
Wed Jun 24, 2009 11:06 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: I need help with this script real quick, small script.
The way you have it, it's checking whether a list exists, and REGARDLESS of whether it does, adding to that list. That means that most of the time it WON'T add to the list properly, or will do other strange stuff.
The way mine is written, it will only add if there IS already a list.
|
Wed Jun 24, 2009 11:11 pm |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: I need help with this script real quick, small script.
You appear to have a missplaced end statement, and the list adding code belongs in Create.
|
Wed Jun 24, 2009 11:14 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: I need help with this script real quick, small script.
No, he's got the correct number of ends, they're just tabbed horribly. Here, this should work, and also isn't terrible syntax. Code: function Create(self) if c4ListS == nil then --If not, create it. c4ListS = { }; else --Add this C-4 to the list. c4ListS[#c4ListS + 1] = self; end end
function Update(self) if (UInputMan:KeyHeld(26)) then self:GibThis(); end end
Last edited by Grif on Wed Jun 24, 2009 11:18 pm, edited 1 time in total.
|
Wed Jun 24, 2009 11:17 pm |
|
|
Foogooman
Joined: Sat Nov 18, 2006 8:11 pm Posts: 267
|
Re: I need help with this script real quick, small script.
Grif wrote: The way you have it, it's checking whether a list exists, and REGARDLESS of whether it does, adding to that list. That means that most of the time it WON'T add to the list properly, or will do other strange stuff.
The way mine is written, it will only add if there IS already a list. Not to be difficult, but I still don't know what to do with that. Where in the code do I put it?
|
Wed Jun 24, 2009 11:17 pm |
|
|
Foogooman
Joined: Sat Nov 18, 2006 8:11 pm Posts: 267
|
Re: I need help with this script real quick, small script.
mail2345 wrote: You appear to have a missplaced end statement, and the list adding code belongs in Create. Like I said, I don't know Lua at all. Could you fix up my script? :[
|
Wed Jun 24, 2009 11:18 pm |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: I need help with this script real quick, small script.
Please avoid double posting in the future. Anyway, even if you don't know Lua, the only way you're going to learn Lua is to figure out how everything fits together. In order to do that, you'll want to learn the syntax first. It's very difficult to help with code that can't be read.
|
Thu Jun 25, 2009 3:56 am |
|
|
|