mob
proc
beam()
var/obj/F = new/obj/beamhead //From now on, F is the beam.
F.dir = src.dir
F.loc = src.loc
while(F) //While the beam still hasn't hit anything...
var/L[]
var/obj/H = new/obj/beamtail
H.dir = F.dir
L=L+H
sleep(2) //Set the speed of beam here
H.loc = F.loc
step(F,F.dir)
var/turf/T = F.loc //For the turfs T has travelled over
if(T.density) //If the turf is dense
del F
for(H in L)
del H
break
else
for(var/mob/M as mob in T)
if(M==src) continue
world<<"[M] has been hit by [src]"
del F
for(H in L) del H
break
Problem description:
Lately, ive just been doing a bunch of mini things to practice up, and my latest thing is trying to get lists to work. I've never been comfortable with lists because they never seem to do what I want. Anyways, I was trying to use it in a beam proc. The problem is, when I check L (the list) for H (the tail of the beam), L doesn't seem to contain anything. I think it has something to do with my method of adding H to L, but i'm not sure. Help please, oh, and please, PLEASE don't just give me the code. If there is a way you can explain just what i'm doing wrong with adding/deleting or something else, that would be great. Examples are ok, just don't give me the working example. Thanks.
That's not how to add an item(s) to a list. What you are doing, is resetting the L var with the value of (L+H) (and trying to calculate it will probably make a runtime error, a type mismatch one). Lists aren't handled the same as numbers etc. If L was a number, then
This isn't the case with lists - you can't add an item to a list the way you've done - you have to use the += operator. This is because the += operator has SPECIAL meaning when used with lists (and the = operator doesn't have it). Using += is equivalent of using the list.Add() procedure - and in fact, it may very well be a shortcut to just that.
Also, I gather you're not actually trying to add 2 items to the list, since if you are then it's stupid since you're adding the list itself to it. Well, you should of understood the right way to add items to the list by now.
So here is the bad line fixed:
Adding multiple items to a list:
I direct you to read the following topics in the DM Reference:
-list operators
-Add proc
-list proc
-list
And just for general knowledge:
-list associations
Note *as suggsted above), lists are actual object datums, (of type /list) and when defining lists, you should always typecast them as /list (otherwise, you can't use list procs).