View unanswered posts | View active topics It is currently Fri Jan 10, 2025 10:27 pm



Reply to topic  [ 14 posts ] 
 OK, seriously, why doesn't this work? 
Author Message
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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.


Sun Apr 25, 2010 5:00 am
Profile WWW
User avatar

Joined: Tue Jan 12, 2010 8:25 pm
Posts: 400
Location: mukilteo, wa
Reply with quote
Post 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.


Sun Apr 25, 2010 5:52 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Sun Apr 25, 2010 6:30 am
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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. :P



EDIT: Oh, and it's just an AHuman and two crabs. No doors this time.


Sun Apr 25, 2010 1:47 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Sun Apr 25, 2010 4:37 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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?)


Mon Apr 26, 2010 9:21 pm
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Mon Apr 26, 2010 9:26 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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.


Attachments:
AC.rte.zip [2.87 KiB]
Downloaded 145 times
Tue Apr 27, 2010 11:11 pm
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: OK, seriously, why doesn't this work?
Try setting them to GetsHitByMOs = 0 when the actor isn't being used.


Tue Apr 27, 2010 11:20 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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.


Tue Apr 27, 2010 11:49 pm
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: OK, seriously, why doesn't this work?
That do you mean by the "mirror image" thing?


Wed Apr 28, 2010 12:01 am
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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.


Wed Apr 28, 2010 12:11 am
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Wed Apr 28, 2010 1:07 am
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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. :grin:


Wed Apr 28, 2010 4:02 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 14 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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.050s | 16 Queries | GZIP : Off ]