ID:141861
 
Code:
statpanel("Inventory")
for(var/obj/X in src.contents)
if(X.type == /obj/magic/spells)
//do nothing
else
stat(X)
statpanel("Spells")
for(var/obj/magic/spells/X in src.contents)
stat(X)


Problem description:
I'm trying to get spells to only appear in the Spells tab, but they appear in the Inventory as well as the Spells tab. What's the problem?

Armiris wrote:
Code:
> statpanel("Inventory")
> for(var/obj/X in src.contents)
> if(istype(X,/obj/magic/spells))
> //do nothing
> else
> stat(X)
> statpanel("Spells")
> for(var/obj/magic/spells/X in src.contents)
> stat(X)
>


Try using the istype() proc in your if() check. Your code doesn't consider sub-types of /obj/magic/spells, so it will skip obj/magic/spells/fireball, for instance.
In response to Xooxer
Thanks, it works now.
Indeed, your problem was that you were directly comparing the obj's type to a given type (the == operator), so that check wouldn't pass unless it was exactly that type, and that's where the istype() proc comes in - it also checks for descendants.
Though, what you probably should really do is make separate lists for inventory and spells. It's tidier than mixing everything together in the same list, and will probably benefit you further along the way as well - it often makes things generally more efficient and simpler, including this:
mob
var/list/spells
Stat()
statpanel("Inventory",src.contents)
statpanel("Spells",src.spells)