ID:147448
 
Okay, so I'm making this spell where it summons monsters into the list I already have for my monsters in battle. Now very rarely it works, but most of the time I get something like this

runtime error: Cannot read null.len
proc name: SummonSlime1 (/mob/monster/SummonSlime1)
source file: MonsterSpells.dm,276
usr: Test Metroid (/mob/Newchar)
src: Healer-B (/mob/monster/Area2/Healer)
call stack:
Healer-B (/mob/monster/Area2/Healer): SummonSlime1(Test Metroid (/mob/Newchar), null)
Healer-B (/mob/monster/Area2/Healer): Spell(Test Metroid (/mob/Newchar), null)
Healer-B (/mob/monster/Area2/Healer): Battle(Test Metroid (/mob/Newchar), null)
Test Metroid (/mob/Newchar): MasterBattle(Healer (/mob/monster/Area2/Healer), null)
Test Metroid (/mob/Newchar): MasterBattle(Healer (/mob/monster/Area2/Healer), null)

I've been tring for the last hour to get this fixed but theres nothing that will work, now here's my code for SummonSlime1
SummonSlime1(mob/Newchar/P,mob/monster/list/enemylist)
var
chance = rand(0,2)
P << "The [src] chants!"
P << 'spell.wav'
sleep(10)
if(chance == 1)
if(enemylist.len>=12) // Line 276
P << "Nothing seemed to happen."
return
else
P << "A Slime appeared!"
var/mob/monster/Summoned/SummonedSlime1/new_mob=new
var/list/letters=list("-A","-B","-C","-D","-E","-F","-G","-H","-I","-J","-K","-L")
var/letter=1
for(var/mob/M in enemylist)
if(M.type==new_mob.type)letter+=1
new_mob.name+=letters[letter]
enemylist+=new_mob
else
P << "Nothing seemed to happen."
sleep(10)


I have marked where Line 276 is because according to the runtime, thats where the problem is. The mob/monster/list/enemylist is the original list from when battle was triggered. I transfered it all the way to this proc. Someone please help, I really need this to work!
runtime error: Cannot read null.len
SummonSlime1(mob/Newchar/P,mob/monster/list/enemylist)

First off with the mob/monster/list/enemylist part I don't think you need the mob/monster/ part since you can define what type of things a list will hold.
>               if(enemylist.len>=12) // Line 276


If enemylist is null then you probably either passed in something null as the parameter to this function or nothing at all.

In response to Theodis
well I initially had it as list/enemylist but I didnt know if it was the reason, so I changed it to that and I still got it, I never had the time to return it to the other way. Also, theres no reason its a null only because my previous codes transfered it there. I dont see why it would be getting null, when I already transfered it. Though, if you want to see my Bump codes and stuff I can get them later, the Bump is what orignally had the list and so I tranfered it from the Bump to the spell. When I get home I can get that.
In response to Metroid
Well regardless if you are intentionally passing in null or not the end result at that proc is that it is null which is why you get the runtime error.
In response to Theodis
Well I said that I transfered it from the proc it comes from which it uses numerous times, and not only that it works rarely but most of the time it does not, why is that?
In response to Metroid
Well I said that I transfered it from the proc it comes from which it uses numerous times, and not only that it works rarely but most of the time it does not, why is that?

I don't know until you post how it's created and used :P.
In response to Theodis
mob/Bump(atom/A)
if(src.battle == 1)
src << "You cannot fight this monster group, for it is already under attack!"
else if(ismob(A))
var/mob/M=A
if(client||M.client)
if(istype(M,/mob/monster))
src.ran = 0
src.dead = 0
amount=rand(1,4)
monstergroup=list()
src.fighting = M
M.fighting = src
src.battle = 1
M.battle = 1
src.islocked = 1
M.islocked = 1
for(var/index=1,index<=amount,index++)
var/mob/enemy=new M.type
enemy.name = "[enemy.name][number2letter(index)]"
src.monstergroup+=enemy
src.monstergroupnumber=src.monstergroup
monster_number="[M.name][plural(monstergroup)]"
MasterBattle(M,monstergroup)


Thats the bump that initialized the combat. From MasterBattle() it goes to Monster's Battle after the player goes, then from there, if the monster chooses a spell and that spell is the code on the first post, it casts it using the monstergroup. Please help.
In response to Metroid
Thats the bump that initialized the combat. From MasterBattle() it goes to Monster's Battle after the player goes, then from there, if the monster chooses a spell and that spell is the code on the first post, it casts it using the monstergroup. Please help.

As indicated by the call stack in the original post I think MasterBattle is called elsewhere with a null second parameter.

call stack:
Healer-B (/mob/monster/Area2/Healer): SummonSlime1(Test Metroid (/mob/Newchar), null)
Healer-B (/mob/monster/Area2/Healer): Spell(Test Metroid (/mob/Newchar), null)
Healer-B (/mob/monster/Area2/Healer): Battle(Test Metroid (/mob/Newchar), null)
Test Metroid (/mob/Newchar): MasterBattle(Healer (/mob/monster/Area2/Healer), null)
Test Metroid (/mob/Newchar): MasterBattle(Healer (/mob/monster/Area2/Healer), null)

The bottom call is the oldest and even there the second parameter is already null. From the code you have posted this should not be a possibility so I'm betting MasterBattle is called elsewhere in an incorrect way.
In response to Theodis
But its only called in the Bump, I can double check...Ahaha! I think I found it, when MasterBattle ends because theres no more turns left, it calls it again, I forgot that and so thats why it would work rarely, because the monsters were casting the spell when the proc was FIRST called. THANKS! Let me test just to make sure...YES! That did it, THANK YOU VERY MUCH! But one last thing, I noticed when monsters were being summoned, it only checked to see if a monster of that type already had a letter (-A, -B,etc.) I want it to go in order no matter thier name. So like theres Healer-A, Healer, B Summoned Slime-C, and Summoned Healer-D (Currently it would make the Summoned Slime be Summoned Slime-A and the Summoned Healer Summoned Healer-A.) how can I make it check the entire list of monsters for the letters? Like right now if they summoned another Slime with that order above, it would make the slime Summoned Slime-B but then if they summoned another Healer it would be Summoned Healer-B. I want to fix that, help please.