ID:140133
 
Code:
proc
My_Turn_Check(mob/m)
var/list/player = Find_Turn_Order(m.battle_datum.Players)
if(player[1] == m)
return 1



battle_datum
var/list
Players = new

//blah blah added players...


Problem description:

The problem is in my "My Turn Check" procedure. I simply want to use it as a quick easy way to check if it's that player's turn.

The Find_Turn_Order procedure works; it simply returns a list of the players in the order of their turns, and we're also assuming battle_datum's player list has players in it.

It's probably something about how I'm setting up the list?
it means that your list isn't as long as 1, so its like your checking for something that never existed in the first place try fixing the code up to make it only check if there even is
a list in there like
proc
My_Turn_Check(mob/m)
var/list/player = Find_Turn_Order(m.battle_datum.Players)
if(!player) return 0
if(player[1] == m)
return 1
else return 0
In response to Masschaos100
Yes but there is definitely players in the list, as far as I know... Unless the datum gets deleted for no reason?
In response to Speedro
Speedro wrote:
Yes but there is definitely players in the list, as far as I know... Unless the datum gets deleted for no reason?

If the datum holding the list were to be deleted the error would be unable to access null.list instead of list index oob.

I suggest doing a bit of testing to see if things are actually being added to the list.
world<<list.len before and after would help you, as well as dumping the contents to see if you're adding what you think you're adding.
Considering the issue is clearly that you are returning an empty list, perhaps you should show us Find_Turn_Order?
In response to Garthor
proc
Find_Turn_Order(list/players)
var/list/turn_order = new
var/mob/temp_lowest

while(players.len)
for(var/mob/m in players)
if(!(temp_lowest) || m.delay < temp_lowest.delay)
temp_lowest = m

//once the above loop is finished we have determined the lowest delay of a player.
turn_order += temp_lowest //add the player to the list in that order
players -= temp_lowest //remove from list to find next lowest delay... repeat.
temp_lowest = null

return turn_order
In response to AJX
Yeah, I was previously doing checks to make sure the list had content. Sometimes it did, but I didn't keep things consistent so it was useless testing. I'll try it again soon.
In response to Speedro
I would throw ASSERT(players && players.len) at the top of Find_Turn_Order. Turn on debugging (#define DEBUG), and when it hits the problem point where Find_Turn_Order() is called with an empty list, you'll get a call stack with the details and some relevant information to help in debugging.
In response to Speedro
The Find_Turn_Order() proc destroys the players list. So, if you call Find_Turn_Order(L), L will be empty afterward. A simple fix is just to copy the list within the proc, though a better solution is to use a not-gofawdul sorting algorithm.
In response to Kuraudo
Yes, it says assertion failed. I'm just not sure why- I have a list, and I'm confident I have put players into the list.

Datum:

Battle_Control
var
Player_Limit
Phase_Count

list
Players = new


New(list/initial_players, conditions_or_messages)
for(var/mob/m in initial_players)
Players += m
world << "[m] has joined the battle!"
Add_Player_Controls(m)
Next_Phase()
//conditions...


Creating Datum:

mob
NPC
delay = 100
verb
fight()
set src in view(1)
new/Battle_Control(list(src,usr)) //initial fighters go in the brackets and terms/conditions.


Next Phase, called on End_Turn:

Battle_Control
proc
Next_Phase()
Phase_Count ++
world << "Phase [Phase_Count]"
var/list/turn_order = Find_Turn_Order(Players)
world << "It is now [turn_order[1]]'s turn!"


And finally, creating the datum:

mob
NPC
delay = 100
verb
fight()
set src in view(1)
new/Battle_Control(list(src,usr)) //initial fighters go in the brackets and terms/conditions.
In response to Garthor
Garthor wrote:
The Find_Turn_Order() proc destroys the players list. So, if you call Find_Turn_Order(L), L will be empty afterward. A simple fix is just to copy the list within the proc, though a better solution is to use a not-gofawdul sorting algorithm.


Heh, here I was all proud of actually creating an algorithm by myself!

However I suppose I knew I was removing things from the player list, I guess I just wasn't smart enough to realize that even when it was passed along it was still effecting the list?