ID:262881
 
Code:
if (Attacker == null)
for (var/mob/M in world)
if (M.BattleNum == BattleCount)
M << "<font face = comic sans ms>\icon[Attacker.Face][Attacker] has logged out in battle!"


Problem description:
runtime error: Cannot read null.IsTurn
proc name: BeginBattle (/mob/proc/BeginBattle)
source file: combat.dm,34
usr: null
src: null
call stack:
BeginBattle(950)
Fight Monsters()

I have traced my error down to this but i have no clue what im doing wrong I think its cause im seting Attacker to null but im not sure plese help


Post the line with the error please
In response to DarkCampainger
ok
var/ContinueBattle = 1   // 1 if battle continues
// The following loop is the battle loop
do
for(var/mob/Attacker in TurnOrder)//this line
if (Attacker != null && Attacker.Hp > 0 && Attacker.BattleNum && ContinueBattle)
Attacker.IsTurn = 1
Attacker << "<font face = comic sans ms>[Attacker], it is now your turn. Attack in 1 minute or your turn will be canceled."
for (var/A = 1; Attacker.IsTurn && A < 120; A++)
if (!Attacker.client)
var/mob/Target
do
for (var/mob/M in TurnOrder)
if (M != Attacker && !rand(0,2))
Target = M
while (Target == null)
Attacker.Attack(Target)
Attacker.IsTurn = 0
sleep(5)
if (Attacker.IsTurn)
Attacker.CheckMyTurn()
var/ContinueTurn = 1
while (Attacker.IsTurn && ContinueTurn)
sleep(5)
var/list/TeamNumList2 = new()
ContinueTurn = 0
var/Count
for (var/mob/M in TurnOrder)
Count ++
if (M.TeamNum == 0 && Count > 1)
ContinueTurn = 1
else
TeamNumList2 += M.TeamNum
if (!ContinueBattle)
for (var/A in TeamNumList2)
for (var/B in TeamNumList2)
if (A != B)
ContinueTurn = 1
if (Attacker == null)
for (var/mob/M in world)
if (M.BattleNum == BattleCount)
M << "<font face = comic sans ms>\icon[Attacker.Face][Attacker] has logged out in battle!"
// Check for players remaining
for (var/mob/M in TurnOrder)
if (M.Hp < 1 || !M)
M << "<font face = comic sans ms>You have been killed!"
M << sound('ff8gover.mid')
TurnOrder -= M
In response to National Guardsmen
Are you sure the line you show as the error line is line 34 of combat.dm? Hit Ctrl+G in your code and type in 34, hit enter, and then repost the 2 lines above it, that line, and the 2 lines under it.

It seems your problem would be more likely near this
                        Attacker.IsTurn = 0
sleep(5)
if (Attacker.IsTurn)
Attacker.CheckMyTurn()
var/ContinueTurn = 1
while (Attacker.IsTurn && ContinueTurn)


Because those are the lines that I immediatly see with IsTurn in them, which is the variable with the error (null.IsTurn, correct?)

Either way, if the above is correct (null.whatever), that means that Attacker is refering to nothing. make sure that Attacker is correctly being transfered from whoever it should be. (if its the player, make sure the player is becoming Attacker, or if the enemy, then that, or whatever)
In response to National Guardsmen
Here's something to remember when using sleep. When you call sleep() the current proc stops and lets other procs run until the number of ticks you passed in as the parameter of sleep is up. During this time the state of the game may have changed(ie players leave, things are killed and/or deleted, etc). So your references which were once good(such as Attacker in your case) may have become null while the proc was sleeping. If this is the case then after calling sleep you should check any references you plan to use and ensure they are still valid. If they aren't you need to come up with some way to safely bail out of the proc or handle it in some other graceful way. In your case you probably want to remove the attacker from the turn order. Check if there are the right number of participants to continue battle and if there are move on without the attacker or if there aren't resolve the battle. Or if the attacker disappeared due to a player leaving or losing their connection you may want to give the option to wait some specific time to give them a chance to return.
This is because when the attacker logs out, attack becomes null(there is no attacker anymore) which is why your getting
runtime error: Cannot read null.IsTurn. Try making a var for the attack once they start the battle, you have attacker as isturn but if there is no attacker it becomes null.isturn

if (Attacker == null)
for (var/mob/M in world)
if (M.BattleNum == BattleCount)
M << "<font face = comic sans ms>\icon[Attacker.Face][Attacker] has logged out in battle!"

//in this
M << "<font face = comic sans ms>\icon[Attacker.Face][Attacker] has logged out in battle!"
//attacker is already null, so it cant tell the world who logged out