ID:173826
![]() Nov 10 2003, 1:59 pm
|
|
i want to know how to make a skill that stretches and doesn't dissapears from its tracks like a missle. do i have to like add objects in every x or y position it passes in a loop, but i don't think that would probably work. do you know any library or demo or tutorial that shows how to do it?
|
Garthor wrote:
obj If you don't understand it, ask a question, don't just plug it in without understanding it. ok. i have it like this and it doesn't work obj beam icon = 'beamshoot.dmi' var/speed = 2 New(turf/T, D) loc = T dir = D if(!step(src, D)) del(src) //If it can't take the step, then end the recursion sleep(speed) //Wait a little bit before making another. new /obj/beam(T, D) //Create a new object. This will freeze until the next object is finished. spawn(10) del(src) //It spawns, so they all delete at once obj Beam_Shoot verb/beam(mob/M in view()) var/DMG = rand(1,usr.STRENGTH) usr <<"beam fire!" new /obj/beam(usr, M) var/obj/beam/b spawn(10) del(b) M.HP -= DMG usr <<"[usr] hits [M] with a beam for [DMG] damage!" no errors or warnings but it doesn't shows on the screen when i use the skill |
The recursive approach here is troubling; this is a very very bad place to use recursion. Get a world big enough and the beam could end up overwhelming your stack. A loop would be a much better choice.
Lummox JR |
Well, I guess you're right. I probably should've put a limit on range. Of course, he has other problems if he has THAT MUCH empty space on his map. With the limit on range, however, I believe this would be a good place to use recursion, because it greatly simplifies the process.
I edited the code snippet to limit the range. |
Well, I guess you're right. I probably should've put a limit on range. Of course, he has other problems if he has THAT MUCH empty space on his map. With the limit on range, however, I believe this would be a good place to use recursion, because it greatly simplifies the process. Well my procs usually crash out after around 130 levels deep of recursing so it is pretty far. If you want to break the recursion just spawn() the creation of the object that way it starts a new call stack rather than just stacking another New() call on top of all the others. |
The point of stacking the new() calls on top of each other is so that the trail deletes itself all at once.
|
The point of stacking the new() calls on top of each other is so that the trail deletes itself all at once. They don't need to be stacked to accomplish that. You'd only need to stack the calls if the return value of calling subsequent new()s mattered. Since the return value is irrelevent you don't need to use recursion. |
If you don't understand it, ask a question, don't just plug it in without understanding it.