ID:142247
 
Code:
mob/verb
Attack()
for(var/mob/M in get_step(src,src.dir))
if(M)
var/obj/Hit/H = new()
H += M.overlays
sleep(10)
H -= M.overlays

obj/Hit
icon = 'Hit.dmi'
New()
pixel_x = rand(0,5)
pixel_y = rand(0.5)


Problem description: Alright, for some strange reason, whenever I try to use the attack verb, I get the runtime error listed below. I honestly do not know what's wrong, although I've worked with attack verbs before -_-'

runtime error: type mismatch: Hit (/obj/Hit) += /list (/list)
proc name: Attack (/mob/verb/Attack)
usr: XeroXen (/mob)
src: XeroXen (/mob)
call stack:
XeroXen (/mob): Attack()
    New(var/obj/Hit/O)
O.pixel_x = rand(0,5)
O.pixel_y = rand(0.5)


I am not sure if you can do that but ive never tried so try this.

    New()
pixel_x = rand(0,5)
pixel_y = rand(0.5)


In response to A.T.H.K
Well, it helped reduce the runtime error, which is good.
In response to XeroXen
Also im not sure if this is the way you wanted it but

H += M.overlays


Should it be the otherway around so H is over the M when the get hit?

M.overlays += H


Hit (/obj/Hit) += /list (/list) - should get rid of this error.
In response to A.T.H.K
Oh, thanks.
In response to XeroXen
Alright, now it's working, but the overlays don't show up, any idea what the problem may be?
mob/verb
Attack()
for(var/mob/M in get_step(usr,usr.dir))
if(M)
var/obj/Hit/H = new()
M.overlays+=H
spawn(10) M.overlays-=H

obj/Hit
icon = 'Hit.dmi'
New(obj/O)
O.pixel_x = rand(0,5)
O.pixel_y = rand(0,5)
Carefully reread every bit of your code when looking for problems. The errors are even more concise these versions - they told you plainly the obvious error of attempting to add a /list object onto an /obj object.
Anyway, your code should be like this:

mob/verb
> Attack()
> for(var/mob/M in get_step(src,src.dir))
//(there is no need to check M and it's pointless)
> M.overlays += /obj/Hit //type paths can be used with overlays as well - this is better and simpler
> spawn(10) //use spawn() so the proc can return
> M.overlays -= /obj/Hit
>
> obj/Hit
> icon = 'Hit.dmi'
> New()
> pixel_x = rand(0,5)
> pixel_y = rand(0,5) //(you had a dot here)
>


I suppose the type path method wouldn't account for the pixel randomization, but 1-5 pixels aren't very noticeable anyway, and using the cleaner, no-objects method is preferable. Of course, you can use constant pixel_* values and have them work by using a type path too, if wanted.
In response to XeroXen
mob/verb
Attack()
for(var/mob/M in get_step(src,src.dir))
M.overlays += /obj/Hit
spawn(10)
H -= /obj/Hit

obj/Hit
icon = 'Hit.dmi'
layer = FLOAT_LAYER //display the obj over the mob
New()
pixel_x = rand(0,5)
pixel_y = rand(0,5)