ID:1859696
 
(See the best response by FKI.)
Code:
mob/Player/Knight
proc
Promotion(mob/Player/M)
M << "You have been appointed as an Knight of [M.Faction]! The standard-issue Knight gear has also been added to your inventory."
Demotion(mob/Player/M)
var/highest = 0.00 //hold the highest KDRatio
var/ties = list() //A list of people with the highest KDRatio for the tiebreaker
for(var/mob/Player/Knight/repl in world) //For every Knight in the world (I dont know how to access the group specifically yet other than the line below)
if(repl.Rank =="Esquire" && repl.Faction == M.Faction) //If repl's rank is below the rank to replace and is part of the group
if(repl.KDRatio > highest) //If repl's KDRatio is higher than highest
ties = new/list(repl) //Add him or her to the list to specify who it is in the world
highest = repl.KDRatio //Set highest to the new highest KDRatio
else if(repl.KDRatio == highest) //If repl's KDRatio is tied for highest
ties.Add(repl) //Add to the ties list
//end of the for loop
if(ties.len > 1) //If there's more than one person with the highest KDRatio in the group
var/mostbattles = 0 //Hold the most/highest amount of battles fought (to find the most experienced)
var/mob/Player/winner //Can I specify the winner in a variable?
for(var/mob/Player/P in ties) //For every Player in ties
if(P.Battles > mostbattles)//If P has fought more battles than the mostbattles count
winner = P //Make P the inner
//end for loop
Promotion(winner)//Call Promotion proc for the winner
else//Otherwise if there is one clear winner
Promotion(ties[1])//Call the Promotion proc for the only element in ties

M << "You have been demoted from Knight to Esquire."


Problem description: I'm trying to create a promotion and demotion system for a group of people (represented by the datum Knight). There can only be a certain number of Knights within a group, which I want to keep track of in a variable in a Faction datum I haven't created yet. The concept I want is when a Prince demotes a Knight, a replacement is found amongst the Esquire, the rank lower. I have it so the demote verb of a Prince calls this proc after the Prince specifies who is being demoted.The Esquire to be promoted has the highest Kills/Death ratio (KDRatio) and, if needed, the most battles fought (Battles). I get the following errors when I compile. Ironically, these are the list operation and variable I pulled from the Help On... What did I do wrong?

loading Knighthood.dme
Ranks.dm:144:error: ties.Add: undefined proc
Ranks.dm:145:error: ties.len: undefined var
Knighthood.dmb - 2 errors, 0 warnings
Best response
var/ties = list()


The compiler doesn't know that it's a list because you didn't typecast it as one.

// one way..
var/ties[] = list()

// or..
var/list/ties = list()
Wow, that's embarrassing. Thanks!