Author |
Message |
Laraso
Joined: Sun Feb 21, 2010 10:40 pm Posts: 97
|
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 |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
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 |
|
|
Laraso
Joined: Sun Feb 21, 2010 10:40 pm Posts: 97
|
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 |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
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 |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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 |
|
|
Laraso
Joined: Sun Feb 21, 2010 10:40 pm Posts: 97
|
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 |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
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 |
|
|
Laraso
Joined: Sun Feb 21, 2010 10:40 pm Posts: 97
|
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 |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Trying to make bombs rain from the sky
|
Fri Dec 24, 2010 4:51 am |
|
|
Laraso
Joined: Sun Feb 21, 2010 10:40 pm Posts: 97
|
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 |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Trying to make bombs rain from the sky
After you define the Bomb.
|
Fri Dec 24, 2010 7:32 am |
|
|
Laraso
Joined: Sun Feb 21, 2010 10:40 pm Posts: 97
|
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 |
|
|
Laraso
Joined: Sun Feb 21, 2010 10:40 pm Posts: 97
|
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 |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Trying to make bombs rain from the sky
Show us the script.
|
Fri Dec 24, 2010 7:09 pm |
|
|
Laraso
Joined: Sun Feb 21, 2010 10:40 pm Posts: 97
|
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 |
|
|
|