Data Realms Fan Forums http://45.55.195.193/ |
|
OK, seriously, why doesn't this work? http://45.55.195.193/viewtopic.php?f=73&t=18593 |
Page 1 of 1 |
Author: | Areku [ Sun Apr 25, 2010 5:00 am ] |
Post subject: | OK, seriously, why doesn't this work? |
A small tidbit of script I was making for a friend: (Props to TLB for the garbage dump script) Code: function Create(self) self.SharedHealthPool = self.Health; self.CurrentState = 1; self.SecondMode = nil; self.ThirdMode = nil; self.ActorsFound = 0; self.timer = Timer(); self.garbTimer = Timer(); local ActorTwo = CreateACrab("Crab"); ActorTwo.Team = self.Team; ActorTwo.Pos.X = -5; ActorTwo.Pos.Y = -5; MovableMan:AddActor(ActorTwo); self.GetSecondActor = ActorTwo; local ActorThree = CreateACrab("Dreadnought"); ActorThree.Team = self.Team; ActorThree.Pos.X = -5; ActorThree.Pos.Y = -5; MovableMan:AddActor(ActorThree); self.GetThirdActor = ActorThree; end function Update(self) if self.timer:IsPastSimMS(25) then if self.ActorsFound == 0 then self.SecondMode = self.GetSecondActor; print (("Actor Found:") .. (self.SecondMode.PresetName)) ; self.ThirdMode = self.GetThirdActor; print (("Actor Found:") .. (self.ThirdMode.PresetName)) ; self.ActorsFound = 1; end if self.CurrentState > 3 then self.CurrentState = 1 end if MovableMan:IsActor(self.SecondMode) and MovableMan:IsActor(self.ThirdMode) then if self.CurrentState == 1 then self.SecondMode.Pos.X = -5; self.SecondMode.Pos.Y = -5; self.ThirdMode.Pos.X = -5; self.ThirdMode.Pos.Y = -5; self.SharedHealthPool = self.Health; self.SecondMode.Health = self.SharedHealthPool; self.ThirdMode.Health = self.SharedHealthPool; elseif self.CurrentState == 2 then self.Pos.X = -5; self.Pos.Y = -5; self.ThirdMode.Pos.X = -5; self.ThirdMode.Pos.Y = -5; self.SharedHealthPool = self.SecondMode.Health; self.Health = self.SharedHealthPool; self.ThirdMode.Health = self.SharedHealthPool; elseif self.CurrentState == 3 then self.Pos.X = -5; self.Pos.Y = -5; self.SecondMode.Pos.X = -5; self.SecondMode.Pos.Y = -5; self.SharedHealthPool = self.ThirdMode.Health self.Health = self.SharedHealthPool; self.SecondMode.Health = self.SharedHealthPool; end if self:IsPlayerControlled() and UInputMan:KeyPressed(26) then self.CurrentState = self.CurrentState + 1; if self.CurrentState == 1 then self.Pos = self.ThirdMode.Pos; self.Vel = self.ThirdMode.Vel; elseif self.CurrentState == 2 then self.SecondMode.Pos = self.Pos; self.SecondMode.Vel = self.Vel; elseif self.CurrentState == 3 then self.ThirdMode.Pos = self.SecondMode.Pos; self.ThirdMode.Vel = self.SecondMode.Vel; end else if MovableMan:IsActor(self.SecondMode) then self.SecondMode.ToDelete = true; print ("Deleted Second actor!"); end if MovableMan:IsActor(self.ThirdMode) then self.ThirdMode.ToDelete = true; print ("Deleted Third actor!"); end self:GibThis(); end self.timer:Reset(); end if self.garbTimer:IsPastSimMS(10000) then collectgarbage("collect"); self.garbTimer:Reset(); end end end So, the purpose of the code is to allow a unit to be replace by other one in real time, cycling through a set of three. However, whenever the starting actor is spawned, it just gibs instantly. Could anyone point me the reason? 'Cause I checked the code several times and still haven't found anything that could be causing this. |
Author: | salt_1219 [ Sun Apr 25, 2010 5:52 am ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
Just curious but what kind of actors are you using? I had a problem like that (likely not the same problem at all) when I made my sandbags using a door actor. I didn't know that I needed a attachment. Anyway I do hope someone who knows lua can help you find the answer. |
Author: | Grif [ Sun Apr 25, 2010 6:30 am ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
um it might have to do with the fact that you're positioning and spawning two actors at the same point as the first unit at the instant of creation or the fact that you've got a GibThis line without any checks on it in an else statement |
Author: | Areku [ Sun Apr 25, 2010 1:47 pm ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
Grif wrote: um it might have to do with the fact that you're positioning and spawning two actors at the same point as the first unit at the instant of creation Eh, no? The first unit stays in place, the others are placed in (-5,-5), outside the map, what turns collisions off for them. I guess. Grif wrote: or the fact that you've got a GibThis line without any checks on it in an else statement Hrmm. That might be the problem. I thought that the 'if' check was enough to prevent it from gibbing, but it might be running into some kinda snag. Gonna add some more ifs. EDIT: Oh, and it's just an AHuman and two crabs. No doors this time. |
Author: | Grif [ Sun Apr 25, 2010 4:37 pm ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
oh wait no I see the problem you don't have enough ends. if self:IsPlayerControlled() and UInputMan:KeyPressed(26) then else self:GibThis() that's how your code reads, because you aren't closing the first statement. Which means that, unless you're controlling the actor AND holding Z, it's immediately going to gib itself. |
Author: | Areku [ Mon Apr 26, 2010 9:21 pm ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
Oh dang, how did I miss that? At any rate, it's fixed now, thanks. And since I'm already here, does anyone know of a way to force the player to switch control to a specific actor? (On an unrelated sidenote, did anyone else notice that trying to position an actor above the Y-limit of the map causes it to spin out of control and gib after a few seconds?) |
Author: | CaveCricket48 [ Mon Apr 26, 2010 9:26 pm ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
Code: ActivityMan:GetActivity():SwitchToActor(<target actor> , <player number> , <target actor's team>); That will switch control of the desired player. To get the player number from a spefic actor that is controlled: Code: actor:GetController().Player Be sure to check if it's controlled before you try to get its player number. |
Author: | Areku [ Tue Apr 27, 2010 11:11 pm ] | ||
Post subject: | Re: OK, seriously, why doesn't this work? | ||
Why, thank ya, mister. Works like a charm. (Well, an unstable, buggy, self-destructing one, but a charm anyways.) EDIT: OK, seriously, now this is **** ridiculous. I feel I'm doing something terribly wrong here, or the game engine hates me to death. Uploading the mod so that you can take a look, and hopefully, tell what is wrong with it.
|
Author: | CaveCricket48 [ Tue Apr 27, 2010 11:20 pm ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
Try setting them to GetsHitByMOs = 0 when the actor isn't being used. |
Author: | Areku [ Tue Apr 27, 2010 11:49 pm ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
I reckon that would help, but it still doesn't solve the "mirror image" thing that appears when the units are positioned. Also, I think I should have put some instructions: just press Z to switch actors. |
Author: | CaveCricket48 [ Wed Apr 28, 2010 12:01 am ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
That do you mean by the "mirror image" thing? |
Author: | Areku [ Wed Apr 28, 2010 12:11 am ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
Well, I guess you'll notice that the two unselected units continually shift through two changing positions near the top of the map, essentially being in two places at the same time. No idea on what causes that. Also, if you change units three times, the third one will fall at incredibly high speed and splatter right into the ground. |
Author: | CaveCricket48 [ Wed Apr 28, 2010 1:07 am ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
That explains alot. Make sure you set the stored actors' velocity to Vector(0,0) every frame, or else gravity will hyper-accelerate them. |
Author: | Areku [ Wed Apr 28, 2010 4:02 am ] |
Post subject: | Re: OK, seriously, why doesn't this work? |
Well, now it works like a charm. Actually, it works so well that I'm even astonished. Thank y'all, guys. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |