⇤ ← Revision 1 as of 2014-04-22 16:30:36
747
Comment:
|
← Revision 2 as of 2015-02-16 14:43:16 ⇥
749
|
Deletions are marked like this. | Additions are marked like this. |
Line 5: | Line 5: |
execute "members = [ " + $result.replace(/^(".*?"),(".*?"),"(.*?)","(.*?)",(".*?"),"(.*?)","(.*?)".*?$/gm, "{ lord:$1, position:$2,prestige:$3,honor:$4,lastlogin:date($5),cities:$6,population:$7 }").split("\n").splice(1).join(",\n") + " ]" | execute "members = [ " + $result.replace(/^(".*?"),(".*?"),"(.*?)","(.*?)",(".*?"),"(.*?)","(.*?)".*?$/gm, "\{ lord:$1, position:$2,prestige:$3,honor:$4,lastlogin:date($5),cities:$6,population:$7 \}").split("\n").splice(1).join(",\n") + " ]" |
This is an example of how to convert CSV output ("members" command in this case) to an array of objects. It also shows how you can process numeric/string/date fields differently and easily sort them.
command "members" execute "members = [ " + $result.replace(/^(".*?"),(".*?"),"(.*?)","(.*?)",(".*?"),"(.*?)","(.*?)".*?$/gm, "\{ lord:$1, position:$2,prestige:$3,honor:$4,lastlogin:date($5),cities:$6,population:$7 \}").split("\n").splice(1).join(",\n") + " ]" top = members.sortOn("prestige", 18)[0] echo "Highest prestige member is " + top.lord + ", prestige=" + FormatNumber(top.prestige) last = members.sortOn("lastlogin", 18)[0] echo "Most recent login is " + last.lord + ", login=" + last.lastlogin