ID:646211
 
Keywords: error, list, typemismatch
(See the best response by NNAAAAHH.)
Code:
        AirSlash
//icon = 'AirSlashHtBx.dmi'
player = 0
scaffold = 0
density = 0
offset_x = 0
offset_y = 0

x_push = 0.5
y_push = 1
hitstun = 3

pwidth = 25
pheight = 25

var //makin the list for down there
list/HitByLinkAirSlash

New(mob/m, sx, sy, vx, vy, dmg)
x_pos = sx
y_pos = sy

dir = m.dir

src.loc = m.loc
set_pos(x_pos, y_pos)

spawn(1.5)
del(src)

movement() // this runs every tick!
for(var/mob/M in oview(1,src))
if(M.inside4(px,py,pwidth,pheight)) //if M is within AirSlashes width and height
if(M.enemy == 1 && !(M in src.HitByLinkAirSlash))//only enemies and NOT in the list
M.damage(M, src.damage, hitstun, dir, x_push, y_push) //OUCH
src.HitByLinkAirSlash += M //add M to AirSlashes HitByLinkAirSlash list


Problem description:
So the AirSlash has a list so that it hits an enemy, adds it to the list, and doesnt attack it again. I thought that was ok, but when I do it in the game, the enemy gets hit multiple times because its not being added to the list somehow!

I get this error

runtime error: type mismatch: the red octorok (/mob/ai/red_octorok) += the red octorok (/mob/ai/red_octorok)
proc name: movement (/mob/pc/Link/AirSlash/movement)
usr: null
src: AirSlash (/mob/pc/Link/AirSlash)
call stack:
AirSlash (/mob/pc/Link/AirSlash): movement(89)
: movement()

I'm not sure whats happening, but it looks like its adding itself to itself or something, but thats not how I have it in the code!

I've gone crazy the past hour
Best response
you define the var to be a list type, but don't specify it to be a list

i assume this is the problem

try putting = list() in there
It's not that he doesn't specify it to be a list, it's that he never initiates the list. var/list/cupcake = list() is one way to initiate it, but a lot of developers say not to do that at compile time. It should be done as it's used, or something.
In response to Super Saiyan X
That's what I was saying, guess I worded it wrongly.
oh em gee thats it?! Thankyou very much guys!
I will point out that your list is entirely useless, since the for loop does just that - it goes through each mob. It will never double over any mobs, unless of course you loop through them again.
In response to Demonking2002
Demonking2002 wrote:
I will point out that your list is entirely useless, since the for loop does just that - it goes through each mob. It will never double over any mobs, unless of course you loop through them again.

It appears to be in a movement loop, so there's a chance (especially with pixel movement) that a mob will be colliding across multiple frames (and the OP doesn't want them to be hit more than once).