ID:141791
 
Code:
    var
list/bodyparts
proc/Binitial()
for(var/E in typesof(/obj/body)-/obj/body)
bodyparts += new E
world << E


Problem description:
runtime error: type mismatch: Adrenals (/obj/body/organs/adrenals) += Adrenals (/obj/body/organs/adrenals)
proc name: Binitial (/mob/proc/Binitial)
usr: ANiChowy (/mob)
src: ANiChowy (/mob)
call stack:
ANiChowy (/mob): Binitial()
ANiChowy (/mob): bodytest()

:(
I have no clue how to fix this, any help?
(Basically, the for() loop is supposed to add all the types of /obj/body to the list bodyparts, also the proc is called by a verb)
Don't forget to initialize the list.
In response to Andre-g1
Even if I do, it still returns the same runtime error.
In response to ANiChowy
That's because at some point you're setting the bodyparts var to a reference to an /obj/body/organs/adrenals object, so it is not a list, therefore the += operator is invalid.
(It's not like I just read the runtime error for you)
In response to Kaioken
The first object it tries to add is /obj/body/organs/adrenals, so I guess the entire error is how it adds the objects to the lists itself, but I have no idea how to fix it.
In response to ANiChowy
The error you're getting is a type mismatch. Like if you try the following :

mob/var/lol="LOL"
mob/var/xD=2

mob/verb/A()
var/AA = lol+xD
world << "[AA]"


Basically like Kaioken said, you're changing the bodyparts value to a non-list value obviously causing an error when you try to add something to it.
In response to Andre-g1
I still can't think of anything to fix the problem.
In response to ANiChowy
...Look for the part in your code that sets bodyparts to the non-list value as discussed above (twice), and remove it?
In response to Kaioken
Which probably would be
bodyparts += new E


that line, but I don't want to remove it because if I did the proc wouldn't do what I wanted it to. I want it to add all the objects derived from /obj/body to the list bodyparts, without the runtime error, of course.
In response to ANiChowy
It's not there, that's adding. You want to look for where it sets the list to a not list value with =.
In response to Jeff8500
That is all the code I have involving that list.
What's with the subtracting?
for(var/E in typesof(/obj/body)-/obj/body)


Just do this
for(var/E in typesof(/obj/body))
In response to Ruben7
Ruben7 wrote:
What's with the subtracting?

It's needed. Though I'd do it with the -= operator instead.
In response to ANiChowy
Apparently doing Var += Value when Var is null just sets it to Value. I was pretty sure that'd give a type mismatch error as per other invalid values used... at any case, this is your problem. But initializing the list properly instead of leaving the variable set to null from the definition should've solved this, unless something fishier is going on.
In response to Kaioken
Kaioken wrote:
It's needed.

How so? I'd just do something like this:
obj
body
head
torso
leg
arm
mob
var
bodyparts[0]
verb/testbody()
usr.Binitial()
proc/Binitial()
for(var/E in typesof(/obj/body))
bodyparts += new E
world << E


PS: I just tested that and no errors for me O.o
In response to Ruben7
Ruben7 wrote:
Kaioken wrote:
It's needed.

How so? I'd just do something like this:
> obj
> body
> head
> torso
> leg
> arm
> mob
> var
> bodyparts[0]
> verb/testbody()
> usr.Binitial()
> proc/Binitial()
> for(var/E in typesof(/obj/body))
> bodyparts += new E
> world << E

PS: I just tested that and no errors for me O.o

Right. Because bodyparts[0] initializes a list.

And the reason for typesof(/obj/body)-/obj/body is to prevent /obj/body from being a part of that list.
In response to Alathon
Alathon wrote:
And the reason for typesof(/obj/body)-/obj/body is to prevent /obj/body from being a part of that list.

typesof(/obj/body) <- I'm guessing that is a tree that branches off into other obj's, why would you subtract the tree itself?

I'm just confused never mind.
In response to Ruben7
The reason is that typesof() simply also includes the parent type used - it returns it back in the list. For something like a container path type, though, you don't want to actually use that base type, so it's removed (you probably get this part).
Go ahead and experiment, run this verb.
obj/myobj
one
two
mob/verb/Test_typesof()
var/list/L = typesof(/obj/myobj)
for(var/x in L)
src << "- [x]"
//could also use a shorter version...but where's the fun in that?
mob/ver/Test_typesof() src << list2params(typesof(/obj/myobj))
In response to Kaioken
Oh he was removing the parent ^^ silly me never mind.

But yeah he probably didn't initialize the list like he claimed to do >.>
In response to Ruben7
Actually, I did do everything right in my proc, the error was with how I was calling the proc.

Seriously, I'm about to slam my head into a wall.