ID:2375755
 
Code:
//The actual individual engagement

obj/engagement
var/list/combatants
var/turn1
var/turn2
density = 0
icon = 'Engagement Flag.dmi'


proc


Turn_Order()
var/hi_spd = 0
var/hi_spd2 = 0
world << "Debug 1"

//Runs through each of the combatants and determines if their speed will allow them into the order.
for(var/mob/player/C in combatants)
world << "Debug 2"
if(C.spd > hi_spd)
world << "Debug 3"
hi_spd = C.spd
turn1 = C
C << "You will take the next turn."
if(C.spd < hi_spd && C.spd > hi_spd2)
world << "Debug 4"
hi_spd2 = C.spd
turn2 = C
C << "You will take the turn after next."

else
return



proc
Start_Engagement()
var/obj/engagement/E = new(locate(13,13,1))
for(var/mob/player/C in view(30))
E.combatants += C
view() << "[C] will be participating in this engagment."
E.Turn_Order()


Problem description: I'm getting started on a combat system that will add nearby users to it's list of combatants then compare their speed to determine their turn order. The issue is when the Turn_Order proc is called, it doesn't seem to be recognizing anyone in the list of combatants, and thus executes none of the coding below the for(). Could someone point me in the right direction?

If "Debug 2" isn't showing up, then your combatants list must not contain any players. So, the problem must be in the code that is supposed to add players to the combatants list: Start_Engagement().

The only thing particularly dangerous about Start_Engagement() is that you're implicitly using usr in each of your view() calls. If you aren't 100% sure that usr is what you need there, you should pass something else instead. This is a global proc, so it's possible that usr is null, view(30) is an empty list, and the loop does nothing.
In response to Kaiochao
Kaiochao wrote:
If "Debug 2" isn't showing up, then your combatants list must not contain any players. So, the problem must be in the code that is supposed to add players to the combatants list: Start_Engagement().

The only thing particularly dangerous about Start_Engagement() is that you're implicitly using usr in each of your view() calls. If you aren't 100% sure that usr is what you need there, you should pass something else instead. This is a global proc, so it's possible that usr is null, view(30) is an empty list, and the loop does nothing.

That makes perfect sense. In fact, I was starting to come to the conclusion that it had something to do with Start_Engagement() being called upon within a player's Login().

It was stuck at Debug 1, and then I realized though I was designating a list of combatants, I wasn't actually creating a new one to add the combatants to. Doing so allowed me to get through to Debug 3.

I assume because the usr of view() is inherently the player that's Login() called for the Start_Engagement(), it's been acting funny.