ID:2892772
 
(See the best response by Lummox JR.)
Code:
mob/verb/Staff()
var
GM
var/savefile/F= new("Staff.sav")
F["GM"] >> GM
for(var/i in GM)
var/html = {"
<HTML><HEAD>
</HEAD>
<BODY BGCOLOR=black TEXT=white>
<p align="center"><font size=5>Staff List</p>
</STYLE>
<hr>
</head>
<body bgcolor=Black bgproperties=fixed>
<font size=2 color=white>GMs"}


if(i.Status == "Online") html += "<p><font size=2 color=white>-[GM] (Online)"
else html += "<p><font size=2 color=white>-[GM] (Offline)"
html += {"
</font>
</body>
</html>
</center>
"}

usr << browse(html,"window=name;file=name;display=1;clear=0; size=300x500;border=0;can_close=1; can_resize=0;can_minimize=1")


Problem description:
Okay so this confuses me a lot x.x so I'll try to explain it.
What I did - When you add a GM in-game it saves their 'key' to a sav file called "staff" in the game's folder as a list.

What I'm trying to do - When you use the 'Staff List' verb in-game I would like it to display all keys in the 'staff' save file AND show if they're online/offline.

The problem - I can get it to display the keys or if they're online or offline which is a var for every client mob called 'status'. Thanks for any help I hope I explained it okay D:.
I've also tried removing the if statements and just using i.Status in [] but it didn't like that either x.x.
Best response
So the first problem is, you're not indenting anything under for(var/i in GM). At least that's how it appears here, which suggests you have some indentation errors. In your code, you're also treating GM like a list in some places and like the mob's key name in another. So there's no consistency whatsoever in what the vars are for.

However the way you're going about saving your staff list is all wrong, and that's the bigger issue. If GM is a list of keys, then you can't use i.Status because i is a key, not a mob. And if you're saving mobs instead of just their keys, you have a whole worse problem.

The first thing I would suggest is not using a savefile for your staff keys. Instead, use a text file.

var/list/staff_keys

proc/SaveStaff()
fdel("staff_keys.txt")
text2file(jointext(staff_keys, "\n"), "staff_keys.txt")
proc/LoadStaff()
var/txt = file2text("staff_keys.txt")
staff_keys = splittext(txt, regex(@"\s*\n\s*"))

Now the rest of your problem is that you need a list of staff mobs. I suggest a global list of players that you can change on the fly when players join, and an associative list by ckey.

var/list/players
var/list/players_by_ckey

mob/player/Login()
... // other login code
(players ||= new) += src
(players_by_ckey ||= new)[ckey] = src

mob/player/Logout()
players -= src
players_by_ckey -= ckey
... // other logout code

Now for your HTML code, here's how I'd build it:

// returns a list of HTML-decorated text that can be joined and inserted in an HTML document
proc/StaffToHTML()
var/mob/M
var/online
. = list()
for(var/sk in staff_keys)
M = players_by_ckey[ckey(sk)]
online = (M && M.status == "Online") ? "Online" : "Offline"
. += "<span class=\"[lowertext(online)]\">[M ? M.key : sk] ([online])</span>"

This code looks up the mob if it exists, and uses their status; if the mob isn't in the players list, then you can use the key from the staff keys list as-is.
T.T I never would have figured all this out idk how you guys are so smart. I'm going to go try and put all this together, thank you!


So this is kind of what I'm looking for btw. This isn't my game but I love the way it's set up so I'm trying to replicate it or at least best I can.
Also I don't think saving it as a .txt would work. I'm using the save file as a way for the game to check against peoples GM status made in-game so I don't have to hard code anyone.
There's no difference between a savefile and a .txt file in that regard; neither one of them is hard-coded. The point of a .txt file though is that it's a better fit for this case, since it can easily be edited while the game is offline. You shouldn't use savefiles for anything as simple as a text list.
Hmmm i get what you're saying and it's not like you would have known I might... but if I ever plan to let others host then wouldn't that be a problem?
If you want to maintain control over who the admins are, then you either have to maintain control over the host files or hard-code the admins. A savefile is not going to be any less susceptible to changing than a text file.
Okay that is totally fair lol I forgot about save file editors. Well thanks so much for all your help, I've learned a ton just from this one thread! :).