ID:1829916
 
(See the best response by Mightymo.)
Code:
/datum/conduit/powernet/proc/merge(var/datum/conduit/powernet/P)
for (var/obj/conduit/power/C in P.children)
C.parent = src

power += P.power
eff += P.eff
children += P.children

del P


Problem description:
In debug mode, Get a type mismatch SOMETIMES but not always.


EXACT ERROR:

runtime error: type mismatch: the power conduit (/obj/conduit/power) += the power conduit (/obj/conduit/power)
proc name: merge (/datum/conduit/powernet/proc/merge)
source file: powernet.dm,43
usr: Emma Hooker (/mob/living/carbon/human)
src: /datum/conduit/powernet (/datum/conduit/powernet)
call stack:
/datum/conduit/powernet (/datum/conduit/powernet): merge(/datum/conduit/powernet (/datum/conduit/powernet))
the power conduit (/obj/conduit/power): build()
the power cable (/obj/item/stack/power_conduit): attackturf(the plating (41,129,1) (/turf/simulated/floor/plating), Emma Hooker (/mob/living/carbon/human))
the plating (41,129,1) (/turf/simulated/floor/plating): attackby(the power cable (/obj/item/stack/power_conduit), Emma Hooker (/mob/living/carbon/human))
the plating (41,129,1) (/turf/simulated/floor/plating): attackby(the power cable (/obj/item/stack/power_conduit), Emma Hooker (/mob/living/carbon/human))
the plating (41,129,1) (/turf/simulated/floor/plating): attackby(the power cable (/obj/item/stack/power_conduit), Emma Hooker (/mob/living/carbon/human))
Emma Hooker (/mob/living/carbon/human): ClickOn(the plating (41,129,1) (/turf/simulated/floor/plating), "icon-x=4;icon-y=10;left=1;scre...")
the plating (41,129,1) (/turf/simulated/floor/plating): Click(the plating (41,129,1) (/turf/simulated/floor/plating), "mapwindow.map", "icon-x=4;icon-y=10;left=1;scre...")
Best response
Are you sure that you are always initializing the list?

siblings = list()
Yes. I've tried with and without.

Alright, looks like i was pointed to the wrong code.

I was declaring the sibling list as "var/list/obj/power/conduit/sibling = list()"
and i guess it didn't like that.
You've edited your code. Your problem is here:
power += P.power


power is a /obj/conduit/power, not a list or a number, so you cannot add them like that.
In response to Nullbear
Nullbear wrote:
I was declaring the sibling list as "var/list/obj/power/conduit/sibling = list()"
and i guess it didn't like that.

You should avoid that when you can. It's best if you avoid initializing any list until you actually need it. But if you do need the list right away, and the datum has a New() proc, initialize the list there instead.

The reason is, constructs like var/list/obj/power/conduit/sibling = list() force the compiler to create a hidden init proc that runs when the object is created. This creates unnecessary overhead.