ID:2035898
 
(See the best response by Nadrew.)
Code:Deleting the rest of the ice trail gone wrong.
    Mage
Ice
verb
Ice_Trail()
if(usr.Ice_Trail_On==0)
if(usr.Mana>100)
var/obj/A = new/obj/Mage/Ice_Magic/Trail/First_Trail(usr.loc)
var/obj/B = new/obj/Mage/Ice_Magic/Trail/Second_Trail(usr.loc)
var/obj/C = new/obj/Mage/Ice_Magic/Trail/First_Trail(usr.loc)
var/obj/D = new/obj/Mage/Ice_Magic/Trail/Second_Trail(usr.loc)
walk_to(A,usr,0,1)
walk_to(B,A,1,1)
walk_to(C,B,1,1)
walk_to(D,C,1,1)
usr.Ice_Trail_On=1
usr.Chikara_Drain()
else
for(var/obj/Mage/Ice_Magic/Trail/First_Trail/A in usr.loc)
del A
for(var/obj/Mage/Ice_Magic/Trail/Second_Trail/B)
del B
for(var/obj/Mage/Ice_Magic/Trail/First_Trail/C)
del C
for(var/obj/Mage/Ice_Magic/Trail/Second_Trail/D)
del D
usr.Ice_Trail_On=0


Problem description:I am trying to make the rest of the ice trail delete both when you click the verb again and when you run out of mana. It only deletes the first one, but when it deletes the others it deletes all others. What should I do?

Best response
You're only setting those variables locally in that verb.

What you'll want to do here is store the pieces as a variable contained by the mob, or just create one object and have it spawn the trails at it moves and contain the list of trail objects in that parent. Either way, here's an example.

mob
var/tmp/list/my_objects

MakeObjects()
if(!my_objects) my_objects = list()
for(var/i=1,i<=4,i++)
var/obj/new_object = new(usr.loc)
my_objects += new_object
walk(new_object,1,2)

DeleteObjects()
if(!my_objects || !my_objects.len) return
for(var/obj/O in my_objects)
del(O)