View unanswered posts | View active topics It is currently Thu Dec 26, 2024 6:32 pm



Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
 Trying to make bombs rain from the sky 
Author Message
User avatar

Joined: Sun Feb 21, 2010 10:40 pm
Posts: 97
Reply with quote
Post Trying to make bombs rain from the sky
I'm trying to make a weapon that when shot, creates an invisible pinned MOSRotating that sits still in the air and runs a .lua that causes bombs to rain from the sky all over the level, then delete itself. The weapon works just fine, and is able to pin the MOSRotating in place to run the .lua, but the .lua doesn't work... I can't figure out what I did wrong. Can someone please look at this and tell me what I did wrong?

Code:
function Create(self)
   self.bombVar = 1
   self.bombTime = Timer()
   self.bombingTime = Timer()
   self.bomb = CreateTDExplosive("Orbital Bomb");
   
end
function Update(self)
   if self.bombVar == 1 then
      if self.bombingTime:IsPastSimMS(100) then
         MovableMan:AddItem(self.bomb)
         self.bomb.Pos = Vector(pos,-20)
         self.bombingTime:Reset()
      end
   end
   if self.bombTime:IsPastSimMS(3000) then
      self.bombVar = 0
      self.ToDelete = true
   end
end


It keeps giving me an error that is something along the lines of "No overload of MovableMan matches blah blah blah". It gives this error constantly, so much so that after shooting the weapon a couple times I get around 3 - 5 frames per second, just from all the errors.

Also, it does drop one bomb, but that is it. It is supposed to drop 30 bombs, randomly around the level, which I don't know how to do. Right now, it drops a single bomb onto the seam of the level, the part where it X-wraps. I want to make it drop them in random positions around the level, but I don't know how.

Normally I just consult the wiki when I need help with lua, but it seems that both the main wiki and the third party wiki are now gone...


Last edited by Laraso on Fri Dec 24, 2010 3:05 am, edited 1 time in total.



Thu Dec 23, 2010 11:26 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Trying to make bombs rain from the sky
Code:
self.bomb = CreateTDExplosive("Orbital Bomb");


This is your problem. Right here..... THIS EXACT LINE.

Its not supposed to be in the Create function, because its only defining it once. Once the function MovableMan:AddParticle() is used then it steals that pointer and that pointer cant be called again. If you put the pointer in the function Update then it should be working, put it like this and it should work right.

Code:
function Create(self)
   self.bombVar = 1
   self.bombTime = Timer()
   self.bombingTime = Timer()
   
end
function Update(self)

   self.bomb = CreateTDExplosive("Orbital Bomb"); -- Now it can use it multiple times since it is creating a pointer every frame.
   if self.bombVar == 1 then

      if self.bombingTime:isPastSimMS(100) then
         MovableMan:AddItem(self.bomb)
         self.bomb.Pos = Vector(pos,-20)
         self.bombingTime:Reset()
      end
   end
   if self.bombTime:isPastSimMS(3000) then
      self.bombVar = 0
      self.ToDelete = true
   end
end


EDIT: Also just for a heads up, if you want it to be 'Permanent' and only created once, then thats when you should put it in the Create Function, Otherwise you might have some slight problems with positioning.


Fri Dec 24, 2010 12:42 am
Profile
User avatar

Joined: Sun Feb 21, 2010 10:40 pm
Posts: 97
Reply with quote
Post Re: Trying to make bombs rain from the sky
Thanks Coops, that solved my problem, but now I have a new problem... The bombs spawn at the same spot like normal, but they spawn so fast that it looks like there is just an image of a bomb sitting there, constantly exploding. I checked the lua console and now it says I am getting vector errors.

I don't really want to fix the vector I have right now, any clues on how to make them spawn in random X positions but at the top of the map?


Fri Dec 24, 2010 3:16 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Trying to make bombs rain from the sky
Code:
Vector(math.random(Scene.Width,-Scene.Width),0)


Fri Dec 24, 2010 3:29 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Trying to make bombs rain from the sky
Your call of Vector(pos,-20) makes no sense, as "pos" hasn't been defined.

Code:
function Create(self)
   --only one timer as we only really want one timed event, nothing complicated.
   self.bombingTime = Timer();
end
function Update(self)
    --hey look one bomb per second!
   if self.bombingTime:isPastSimMS(1000) then
      --make the bomb only when needed, and store it locally.
      local bomb = CreateTDExplosive("Orbital Bomb");
      --put the bomb at a random position.
      bomb.Pos = Vector(math.random(10000),-20);
      -- anyway, I don't have the sceneman docs with me at the moment, so I'm just using a very large number.
      --now that the bomb's created and in position, add it to the scene
      MovableMan:AddItem(bomb);
      self.bombingTime:Reset(); --and then reset the timer so we can use it again
   end
end


I have no idea what all you guys were playing at :/


Fri Dec 24, 2010 3:37 am
Profile WWW
User avatar

Joined: Sun Feb 21, 2010 10:40 pm
Posts: 97
Reply with quote
Post Re: Trying to make bombs rain from the sky
I had two timers because it was supposed to make lots of bombs in a short time period. If bombVar = 1, then after 100 MS, it would create a bomb. If 3000 MS had passed, bombVar would be set to 0 to stop making bombs, and then the MOSRotating would delete itself. At least, thats how its supposed to work.


Fri Dec 24, 2010 4:17 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Trying to make bombs rain from the sky
The try something like this.

Code:
function Create(self)
   self.bombTime = Timer();
   self.bombingTime = Timer();
end
function Update(self)
   if self.bombTime:isPastSimMS(1000) then
      local bomb = CreateTDExplosive("Orbital Bomb");
      bomb.Pos = Vector(math.random(Scene.Width,-(SceneWidth)),-20);
      MovableMan:AddItem(bomb);
      self.bombTime:Reset();
   end
   if self.bombTime:isPastSimMS(3000) then
      self.ToDelete = true
   end
end


Fri Dec 24, 2010 4:25 am
Profile
User avatar

Joined: Sun Feb 21, 2010 10:40 pm
Posts: 97
Reply with quote
Post Re: Trying to make bombs rain from the sky
Yeah, I tried your Scene.Width thing, but it gave me errors in the lua console. It said that Width for Scene had not yet been defined.

I just took the code I had originally and replaced the vector with geti's vector, it works fine now. Thanks everyone for your help.

EDIT:

Actually, one more thing... How do I make it so the bombs that are spawned don't have names above them? Do I have to change them from TDExplosive to MOSRotating?


Fri Dec 24, 2010 4:41 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Trying to make bombs rain from the sky
Code:
bomb:IsActivated()


Fri Dec 24, 2010 4:51 am
Profile
User avatar

Joined: Sun Feb 21, 2010 10:40 pm
Posts: 97
Reply with quote
Post Re: Trying to make bombs rain from the sky
I'm afraid that doesn't work. Is there any specific location I have to put that?


Fri Dec 24, 2010 5:25 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Trying to make bombs rain from the sky
After you define the Bomb.


Fri Dec 24, 2010 7:32 am
Profile
User avatar

Joined: Sun Feb 21, 2010 10:40 pm
Posts: 97
Reply with quote
Post Re: Trying to make bombs rain from the sky
That is exactly where I have it now, it doesn't work.


Fri Dec 24, 2010 3:10 pm
Profile
User avatar

Joined: Sun Feb 21, 2010 10:40 pm
Posts: 97
Reply with quote
Post Re: Trying to make bombs rain from the sky
I don't know why everyone is seeing it written as a lowercase i, but if you look at the OP you can see they are all capital.

Also, any advice on how to prevent names from appearing over the bombs would be appreciated.


Fri Dec 24, 2010 4:06 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Trying to make bombs rain from the sky
Show us the script.


Fri Dec 24, 2010 7:09 pm
Profile
User avatar

Joined: Sun Feb 21, 2010 10:40 pm
Posts: 97
Reply with quote
Post Re: Trying to make bombs rain from the sky
Code:
function Create(self)
   self.bombVar = 1
   self.bombTime = Timer();
   self.bombingTime = Timer();
end
function Update(self)
   if self.bombVar == 1 then
      if self.bombingTime:IsPastSimMS(50) then -- set to lower number for more bombs
         self.bomb = CreateTDExplosive("Orbital Bomb");
         self.bomb:IsActivated()
         MovableMan:AddItem(self.bomb);
         self.bomb.Pos = Vector(math.random(10000),-20);
         self.bombingTime:Reset();
      end
   end
   if self.bombTime:IsPastSimMS(10000) then -- set to higher number for longer bombing time
      self.bombVar = 0
      self.ToDelete = true
   end
end


It really isn't much different than last time. It works just fine, but the name of the bomb appears above them.


Fri Dec 24, 2010 7:26 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 25 posts ]  Go to page 1, 2  Next

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.080s | 13 Queries | GZIP : Off ]