ID:1482568
 
Code:
#define SCOREBOARD_SAVEFILE "World/Saves/Scoreboard.sav"

var/Scoreboard/theScoreboard

proc/Scoreboard_Load()
if(fexists(SCOREBOARD_SAVEFILE))
var/savefile/F = new(SCOREBOARD_SAVEFILE)
F["Scoreboard"] >> theScoreboard
if(theScoreboard) return
theScoreboard=new

proc/Scoreboard_Save()
if(fexists(SCOREBOARD_SAVEFILE)) fdel(SCOREBOARD_SAVEFILE)
var/savefile/F = new(SCOREBOARD_SAVEFILE)
F["Scoreboard"] << theScoreboard

proc/Scoreboard_add(var/ckey, var/level, var/display_name, var/house)
if(!ckey || !level || !display_name || !house)
world.log << "Missing key, level, display_name, or house in Scoreboard_add proc."
return
if(!theScoreboard) Scoreboard_Load()
while(theScoreboard.in_use) sleep(1)
theScoreboard.in_use = 1
ckey = ckey(ckey)
var/pos
var/ScoreboardEntry/se
if(theScoreboard.entries)
pos = theScoreboard.entries.Find(ckey)
if(pos)
se = theScoreboard.entries[ckey]
if(se.level == level)
theScoreboard.in_use = 0
return
if(se.level > level)
theScoreboard.entries -= ckey
pos = 0
se = null
else
se.level = level
se.display_name = display_name
se.house = house
if(!se) se = new(ckey, level, display_name, house)
if(theScoreboard.Sort_entry(se, pos)) Scoreboard_Save()
theScoreboard.in_use = 0

ScoreboardEntry
var
name //KEY
level
display_name
timestamp
house
New(var/name, var/level, var/display_name, var/house)
src.name = name
src.level= level
src.display_name = display_name
src.timestamp = time2text(world.realtime, "\[MM/DD/YY @ hh:mm\]")
src.house = house

Scoreboard
var/const/max_entries = 50 //0 means unlimited
var/tmp/in_use = 0
var/list/entries
var/html_cache
var/const/styles = {"
<style type="text/css">
body{
background-color:#000000;
font-family:Tahoma;
color:#FFFFFF;
font-size:2px;
margin: 0px;
padding: 12px 0px 4px 20px;
}
p#number {text-align:right; color: white;}
p#timestamp {text-align:center; color: white;}
p#level {text-align:center; color: white;}
p#name {text-align:left;}

table#score {
background-color: #000000;
padding: 0px;
width: 100%;
border: solid 1px #2E2E2E;
}

td#number {background-color: #404040;}
td#name {background-color: #303030;}
td#level {background-color: #404040;}
td#timestamp {background-color: #303030;}

tr#categories{
background-color: #2E2E2E;
color: #ffffff;
padding-left: 10px;
padding-right: 10px;
border-bottom: solid 1px #2E2E2E;
text-decoration: none;
font-size: 95%;
}
</style>
"}

proc/Sort_entry(var/ScoreboardEntry/entry, var/starting_pos)
ASSERT(entry)
if(!src.entries) {src.entries=list(); src.append(entry, 1); return}
var/ScoreboardEntry/currentEntry
if(!starting_pos) starting_pos = src.entries.len
else src.entries -= entry.name
starting_pos = min(starting_pos, src.entries.len)
for(var/i=starting_pos to 1 step -1)
currentEntry=src.entries[src.entries[i]]
if(currentEntry.level > entry.level) {src.append(entry, i+1);break}
if(currentEntry.level == entry.level) {src.append(entry, i); break}
if(i==1) src.append(entry, 1)
return 1

proc/append(var/ScoreboardEntry/entry, var/pos)
ASSERT(entry && pos>0 && src.entries)
src.entries.Insert(pos, entry.name)
src.entries[entry.name]=entry
entry.timestamp = time2text(world.realtime, "\[MM/DD/YY @ hh:mm\]")
if(src.max_entries && src.entries.len>src.max_entries) src.entries.Cut(src.max_entries+1)
src.BuildHTMLCache()

proc/BuildHTMLCache()
var/html = {"
<html><head>
[src.styles]<title>[world.name]'s Scoreboard</title></head>
<body><table id='score'><tr id='categories'>
<td id='number'><p id='number'>#</p></td>
<td id='house'><p id=
<td id='score'><p id='name'>Name</b></td>
<td id='score'><p id='level'>Level</b></td>
<td id='score'><p id='timestamp'>Timestamp</p></td>
</tr>"}

//var/counter = 0
for(var/i=1 to src.entries.len)
var/ScoreboardEntry/entry=src.entries[src.entries[i]]
html+={"<tr>
<td id='number'><p id='number'>
[i]</p></td>
<td id='name'><p id='name'>
[entry.display_name]</p></td>
<td id='level'><p id='level'>
[entry.level]</p></td>
<td id='timestamp'><p id='timestamp'>
[entry.timestamp]</p></td>
</tr>"}

html += "</table></body></html>"
html_cache = html


mob/Player/verb/Scoreboard()
if(!theScoreboard)
Scoreboard_Load()
if(!theScoreboard)
usr << "The scoreboard is currently out of order."
return
var/html = theScoreboard.html_cache
if(!html) html = "The scoreboard has not run any listings."
usr << browse(html, "window=scoreboard;size=400x600")


Problem description:
Well, recently I have tried to fix a scoreboard system. It used to work before, but it doesn't anymore for quite a while now. I have been trying to figure out where it goes wrong. The problem is that the Scoreboard only shows the first html_cache that has been generated. And the problem is that I don't know where it goes wrong in the process of creating an updated one. It has been troubling my mind for days, so I decided to post it here. Does anyone has a clue?
Bump, anyone?
I ran your code and apart from a BYOND bug in the stable release there doesn't seem to be anything wrong at first sight (other than your code style, ahem).

The scoreboard lists multiple entries just fine so long as the name for each entry is different.

If this doesn't help you then you'll have to elaborate on your problem a bit more.
In response to Sir Lazarus
My problem is that the scoreboard only gets updated once when a player has logged in at the start of the world (server). After that, it doesn't seem to update anymore after other players log in thus only one entry showing, the one from the player who logged in as first.

Deleting the save file only helps for getting a fresh scoreboard, but then again only one player shows up for the rest of the savefile's existence.

It also doesn't update the level of the player showing up as the only one on the scoreboard. So, the scoreboard only seems to be created once, and then breaks for some reason I don't know.
Create save points for them then?
In response to Dopenaruto
Dopenaruto wrote:
Create save points for them then?

If you actually read my snippet, I am..
In response to Raimo
Raimo wrote:
My problem is that the scoreboard only gets updated once when a player has logged in at the start of the world (server). After that, it doesn't seem to update anymore after other players log in thus only one entry showing, the one from the player who logged in as first.

Sounds like the problem might be in a different area. Could you post the code for your login process?