Data Realms Fan Forums http://45.55.195.193/ |
|
I need help with this script real quick, small script. http://45.55.195.193/viewtopic.php?f=73&t=15547 |
Page 1 of 1 |
Author: | Foogooman [ Wed Jun 24, 2009 10:51 pm ] |
Post subject: | 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 |
Author: | Grif [ Wed Jun 24, 2009 11:04 pm ] |
Post subject: | Re: I need help with this script real quick, small script. |
if not C4ListS then c4ListS = { }; else c4ListS[#c4ListS + 1] = self; end |
Author: | Foogooman [ Wed Jun 24, 2009 11:06 pm ] |
Post subject: | 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. |
Author: | Grif [ Wed Jun 24, 2009 11:11 pm ] |
Post subject: | 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. |
Author: | mail2345 [ Wed Jun 24, 2009 11:14 pm ] |
Post subject: | 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. |
Author: | Grif [ Wed Jun 24, 2009 11:17 pm ] |
Post subject: | 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 |
Author: | Foogooman [ Wed Jun 24, 2009 11:17 pm ] |
Post subject: | 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? |
Author: | Foogooman [ Wed Jun 24, 2009 11:18 pm ] |
Post subject: | 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? :[ |
Author: | TheLastBanana [ Thu Jun 25, 2009 3:56 am ] |
Post subject: | 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. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |