| Author | Message | 
        
			| Awesomeness 
					Joined: Sat Jun 19, 2010 5:02 pm
 Posts: 331
 Location: Mekkan
   |   2 small questionsThanks for reading!     Question 1: How can I create a timer that measures real-world time, not in-game time?  I need to time music. Question 2:  If I have a reference to an actor, how can I gib specifically that actors head, if said actor owns a head?  I tried: Code: if actor.Head ~= nil thenactor.Head:GibThis();
 end
But this failed.
 
 | 
		
			| Sat Aug 06, 2011 4:01 am | 
					
					   | 
	
	
		|  | 
	
			| Roast Veg Data Realms Elite 
					Joined: Tue May 25, 2010 8:27 pm
 Posts: 4522
 Location: Constant motion
   |   Re: 2 small questionsWhy would you need to measure the length of music anyway? If you need to play a tune after it you can add it to the queue. 
 
 | 
		
			| Sat Aug 06, 2011 4:06 am | 
					
					   | 
	
	
		|  | 
	
			| Coops 
					Joined: Wed Feb 17, 2010 12:07 am
 Posts: 1545
 Location: That small peaceful place called Hell.
   |   Re: 2 small questions1: this for Miliseconds. Code: yourTimer.ElapsedRealTimeMSand this for Seconds Code: yourTimer.ElapsedRealTimeS2: Try this instead. Code: --get your actor
 if actor.Head:IsAttached() then
 actor.Head:GibThis()
 end
 
 
 
 | 
		
			| Sat Aug 06, 2011 4:13 am | 
					
					   | 
	
	
		|  | 
	
			| Awesomeness 
					Joined: Sat Jun 19, 2010 5:02 pm
 Posts: 331
 Location: Mekkan
   |   Re: 2 small questionsI need to know when to blow up something after a song ends lol... How can I make sure it doesn't throw an error when the reference happens to be to something that never had a head? (Dropships, doors) You'll see how this all comes together when I release a small mod soon....  
 
 | 
		
			| Sat Aug 06, 2011 12:38 pm | 
					
					   | 
	
	
		|  | 
	
			| Coops 
					Joined: Wed Feb 17, 2010 12:07 am
 Posts: 1545
 Location: That small peaceful place called Hell.
   |   Re: 2 small questionsCode: -- Make sure you have make this check AFTER the music started-- Get "whatever"
 
 if not AudioMan:IsMusicPlaying() then
 whatever:GibThis()
 end
 
Code: for act in MovableMan.Actors doif -- your actor checks then
 if act.ClassName == "AHuman" then
 local actor = ToAHuman(act)
 break
 end
 end
 end
 
 if actor then
 if actor.Head:IsAttached() then
 actor.Head:GibThis()
 end
 else
 actor = nil
 end
 
Second one might be tricky though, thats the only way I know how to do it.
 
 | 
		
			| Sat Aug 06, 2011 12:54 pm | 
					
					   | 
	
	
		|  | 
	
			| Abdul Alhazred DRL Developer 
					Joined: Tue Aug 11, 2009 5:09 am
 Posts: 395
   |   Re: 2 small questionsYou can check for nil first, since only AHumans have a Head pointer. Remember that in Lua nil is equivalent to a logical false so you can do it like this: Code: if Target.Head and Target.Head:IsAttached() thenTarget.Head:GibThis()
 end
 
 | 
		
			| Sat Aug 06, 2011 9:15 pm | 
					
					   | 
	
	
		|  | 
	
			| Awesomeness 
					Joined: Sat Jun 19, 2010 5:02 pm
 Posts: 331
 Location: Mekkan
   |   Re: 2 small questionsI put that snippet in...  No errors.  It just refused to blow up heads.This LuaDoc  tells me Head is read-only.  Does that mean I can't gib it? Because that would explain. Also... Is it possible to attach a glow to an MOSRotating?
 
 | 
		
			| Sun Aug 07, 2011 2:10 am | 
					
					   | 
	
	
		|  | 
	
			| CaveCricket48 
					Joined: Tue Jun 12, 2007 11:52 pm
 Posts: 13144
 Location: Here
   |   Re: 2 small questionsNot with any (functional) INI method. What you want to do is create a MOPixel that has a glow, and use Lua to position the MOPixel correctly over the MOSRotating. 
 
 | 
		
			| Sun Aug 07, 2011 4:51 am | 
					
					   | 
	
	
		|  | 
	
			| Abdul Alhazred DRL Developer 
					Joined: Tue Aug 11, 2009 5:09 am
 Posts: 395
   |   Re: 2 small questionsAwesomeness wrote: I put that snippet in...  No errors.  It just refused to blow up heads.Coops9753 script looks correct, but you cannot just copy it because of the comment in the if-statement. Try this: Code: function Update(self)for Act in MovableMan.Actors do
 if Act.ClassName == "AHuman" then
 Act = ToAHuman(Act)
 if Act.Head and Act.Head:IsAttached() then
 Act.Head:GibThis()
 end
 end
 end
 end
Awesomeness wrote: This LuaDoc tells me Head is read-only.  Does that mean I can't gib it? Because that would explain.It means you cannot change what the pointer is pointing to, meaning it is not possible to e.g. replace a head with a new one.
 
 | 
		
			| Sun Aug 07, 2011 12:30 pm | 
					
					   | 
	
	
		|  | 
	
			| Awesomeness 
					Joined: Sat Jun 19, 2010 5:02 pm
 Posts: 331
 Location: Mekkan
   |   Re: 2 small questionsOh...  I know what you mean.  I am very familiar with references and pointers in Java... Usually they're super helpful, but in some moments when you have to use clone(), they are infuriating    EDIT:  Okay, um...  It still failed to blow up heads.  I did some print debugging. It only prints "Found AHuman!" over and over again. Code:    for actor in MovableMan.Actors doself.Distance = math.sqrt(math.pow(self.Pos.X - actor.Pos.X,2) + math.pow(self.Pos.Y - actor.Pos.Y,2));
 if self.Distance < 200 then
 
 if actor.ClassName == "ACrab" then
 actor:GibThis();
 print("Gibbed a crab!");
 end
 
 if actor.ClassName == "AHuman" then
 actor = ToAHuman(actor);
 if actor.Head and actor.Head:IsAttached() then
 actor.Head:GibThis();
 print("Blew up a head!");
 else
 print("Found AHuman!");
 end
 end
 
 end
 end
 
 | 
		
			| Sun Aug 07, 2011 2:47 pm | 
					
					   | 
	
	
		|  | 
	
			| Abdul Alhazred DRL Developer 
					Joined: Tue Aug 11, 2009 5:09 am
 Posts: 395
   |   Re: 2 small questionsI cannot see why it is not working, so I modified a bit and then tested it to make sure it works. Code: function Update(self)for actor in MovableMan.Actors do
 if SceneMan:ShortestDistance(self.Pos, actor.Pos, false).Magnitude < 200 then    -- just calculating the hypotenuse will cause problems around the map seam
 if actor.ClassName == "ACrab" then
 actor:GibThis()
 elseif actor.ClassName == "AHuman" then
 actor = ToAHuman(actor)
 if actor.Head and actor.Head:IsAttached() then
 actor.Head:GibThis()
 end
 end
 end
 end
 end
 
 
 | 
		
			| Sun Aug 07, 2011 3:27 pm | 
					
					   | 
	
	
		|  | 
	
			| Awesomeness 
					Joined: Sat Jun 19, 2010 5:02 pm
 Posts: 331
 Location: Mekkan
   |   Re: 2 small questionsOkay... it's still not working.  This is my full code... Code: function Create(self)AudioMan:ClearMusicQueue();
 AudioMan:PlayMusic("Friday.rte/Friday.ogg", 0, -1);
 self.GibTimer = Timer();
 self.GibTimer:Reset();
 self.SupposedToBeAlive = true;
 end
 function Update(self)
 if self.GibTimer.ElapsedRealTimeMS > 227*1000 then
 self.SupposedToBeAlive = false;
 self:GibThis();
 end
 for actor in MovableMan.Actors do
 if SceneMan:ShortestDistance(self.Pos, actor.Pos, false).Magnitude < 200 then    -- just calculating the hypotenuse will cause problems around the map seam
 if actor.ClassName == "ACrab" then
 actor:GibThis()
 elseif actor.ClassName == "AHuman" then
 actor = ToAHuman(actor)
 if actor.Head and actor.Head:IsAttached() then
 actor.Head:GibThis()
 end
 end
 end
 end
 if self.SupposedToBeAlive == true then
 self.ToDelete = false;
 self.ToSettle = false;
 end
 end
 function Destroy(self)
 AudioMan:ClearMusicQueue();
 AudioMan:PlayMusic("Base.rte/Music/dBSoundworks/cc2g.ogg", -1, -1);
 print("Gone!");
 print(self.GibTimer.ElapsedRealTimeMS/1000);
 end
 
What stupid error am I making in my code that makes it silently fail to work?    
 
 | 
		
			| Sun Aug 07, 2011 4:57 pm | 
					
					   | 
	
	
		|  | 
	
			| Coops 
					Joined: Wed Feb 17, 2010 12:07 am
 Posts: 1545
 Location: That small peaceful place called Hell.
   |   Re: 2 small questionsWhat is the script attached to? 
 
 | 
		
			| Sun Aug 07, 2011 5:04 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: 2 small questionsYou may want to set the third argument of SceneMan:ShortestDistance to true. Otherwise, it won't account for wrapping over the map's seam.Actually, don't do that. See Abdul's post.
 
 
 | 
		
			| Sun Aug 07, 2011 7:06 pm | 
					
					     | 
	
	
		|  | 
	
			| Awesomeness 
					Joined: Sat Jun 19, 2010 5:02 pm
 Posts: 331
 Location: Mekkan
   |   Re: 2 small questionsThe script is attached to an MOSRotating that doesn't move.  And I'll change that to true.  It's still not working...   
 
 | 
		
			| Sun Aug 07, 2011 7:40 pm | 
					
					   | 
	
	
		|  | 
	
	
		|  |