Data Realms Fan Forums http://45.55.195.193/ |
|
Selectively removing things from lists http://45.55.195.193/viewtopic.php?f=73&t=15567 |
Page 1 of 1 |
Author: | Asatruer [ Fri Jun 26, 2009 1:31 am ] |
Post subject: | Selectively removing things from lists |
Yet another C4 lua related question. The normal vanilla C4, and the recent mods based on it, use the creation of a list so the detonator can tell all the C4 bombs on that list to explode. I have run into a problem mucking with that code where I have a Proximity sensor that detects any actor within a small radius, then detonates the C4 spray in a larger radius. I have that part working, but there is a bug in there that sometimes causes CC to crash to desktop. My best guess is that since the Proxy Detonator is exploding only some of the C4 spray in the list and not clearing the list--like the normal detonator does--that when another call to detonate the spray that is already detonated crashes the game. So, to check to see if this is what is causing the problem, and to solve it if it is, the script needs to remove the detonated c4 spray from the list when it is detonated. I have not had any luck figuring out how to go about doing that, anyone have an idea? |
Author: | mail2345 [ Fri Jun 26, 2009 1:49 am ] |
Post subject: | Re: Selectively removing things from lists |
When it's created, track it's own list location. THen set lisst[lisstlocation] to nil. |
Author: | Geti [ Fri Jun 26, 2009 4:47 am ] |
Post subject: | Re: Selectively removing things from lists |
in other words, when you add it to the list in create(self), add this Code: self.thisC4 = #<listname> Code: table.remove(<listname>, self.thisC4) edit:typos <_< |
Author: | mail2345 [ Fri Jun 26, 2009 4:48 am ] |
Post subject: | Re: Selectively removing things from lists |
table.remove shifts things down the list, invalidating the thisc4 variables. |
Author: | Asatruer [ Fri Jun 26, 2009 5:37 am ] |
Post subject: | Re: Selectively removing things from lists |
So here was my blind stab at trying to get lucky implementing that Code: function Create(self) if c4ListS == nil then c4ListS = { }; end c4ListS[#c4ListS + 1] = self; self.thisC4 = #c4ListS end function Destroy(self) c4ListS[self.thisC4] = nil; end I am not getting any CtDs, but the first explosion--detonated by the proxy mine--does not always explode all of the c4 within range, and then following detonations usually do not work and give the following error Code: proxydetonator.lua:19: attempt to index field '?' (a nil value) since it will probably help to show it, proxydetonator.lua look like Code: function Create(self) self.explosion = CreateAEmitter("Explosion Sound"); end function Update(self) for actor in MovableMan.Actors do local avgx = actor.Pos.X - self.Pos.X; local avgy = actor.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if dist < 50 then self:GibThis() end end end function Destroy(self) for i=1,#c4ListS do if MovableMan:IsParticle(c4ListS[i]) then self.explosion.Pos = c4ListS[1].Pos; --Line 19... hah, I see what the problem is now for p in MovableMan.Particles do local avgx2 = p.Pos.X - self.Pos.X; local avgy2 = p.Pos.Y - self.Pos.Y; local dist2 = math.sqrt(avgx2 ^ 2 + avgy2 ^ 2); if dist2 < 150 then if p.PresetName == "C4 Spray Filler" or p.PresetName == "Active C4 Spray Filler" then p.Lifetime = 1 elseif (c4ListS[i].Pos - p.Pos).Magnitude < 5 then p.Vel = Vector(p.Vel.X * 1.25, p.Vel.Y *1.25) c4ListS[i]:GibThis(); MovableMan:AddParticle(self.explosion); end --c4ListS[i]:GibThis(); end end end end --c4ListS = { }; end OK... Apparently I need to get the list position for the first non-nil entry for placing the sound effect. |
Author: | Geti [ Fri Jun 26, 2009 7:25 am ] |
Post subject: | Re: Selectively removing things from lists |
mail2345 wrote: table.remove shifts things down the list, invalidating the thisc4 variables. really? good to know, thanks mail. |
Author: | mail2345 [ Fri Jun 26, 2009 7:31 am ] |
Post subject: | Re: Selectively removing things from lists |
Figured that out after an hour's worth of muttering "What the ♥♥♥♥!" at my laptop. Anyway try: Code: if not(soundexpposset) and c4ListS[i] ~= nil then self.explosion.Pos = c4ListS[i].Pos; soundexpposset = true end And in create: Code: soundexpposset = false |
Author: | Asatruer [ Fri Jun 26, 2009 7:41 pm ] |
Post subject: | Re: Selectively removing things from lists |
Is it safe to assume that the true/false status on that will be specific to individual proxy sensors and not for all proxy sensors? |
Author: | mail2345 [ Fri Jun 26, 2009 7:43 pm ] |
Post subject: | Re: Selectively removing things from lists |
Whoops! Forgot about that. Just add self. infront of soundexpposset |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |