ID:1442369
 
(See the best response by Ter13.)
Hey guys, me again, I've been trying to get this simple bit of code to work for well... Quite a bit of time now, but overall.. It just doesn't work. My assumptions are that the list isn't created, but it should..
I was hoping there's people capable of helping me with this code, which may come off as weird, or completely non-functional..
EDIT: Code comes to number 155, then stops.

/mob
var/savefile/medals = null
var/list/medalslist = list()

/mob/New()
..()
medals = new("data/player_saves/[copytext(src.ckey, 1, 2)]/[src.ckey]/medals.sav")
if(medals)
load_medals(src)

/mob/proc/give_medal(mob/user)
if(!check_rights(R_ADMIN)) return
world << "0"
if(user)
world << "1"
var/medalname = input("What is the medal's name?", "Medal Name", "Medal Of")
var/medaldesc = input("What is the medal for?", "Medal for what?", "Medal given for")
world << "2"
// if(medalname && medaldesc)
var/message = "Medal of [medalname] - [medaldesc] awarded by [usr.ckey]"
world << "155"
if(user && user.medalslist)
world << "156"
user.medalslist.Add(message)
world << "145"
world << "<font color='3cbc2b'><b>Player [user.client] has been awarded the [medalname], for [medaldesc]!</b></font>"
save_medals(user)

/mob/proc/save_medals(var/mob/player)
medals["medallist"] << player.medalslist
// medals["medallist"] << dd_list2text(player.medalslist, "\n")

/mob/proc/load_medals(var/mob/player)
medals["medallist"] >> player.medalslist
// medals["medallist"] >> text2list(player.medalslist, "\n")


/mob/Stat()
statpanel("Medals")
stat("Medals Awarded to you:", dd_list2text(medalslist,"\n"))


/mob/verb/grant_medal(mob/M)
set name = "Grant Medal"
set category = "Admin"
set src in view(usr) //If it can be seen, it can be examined.
world << "11"
give_medal(M)
world << "12"


Problem description:
Problem explained on top.

I hope someone can see the issue and tell me what it was that I did wrong, it'd help me a lot!
Thanks in advance.
Best response
/mob/verb/grant_medal(mob/M)
set name = "Grant Medal"
set category = "Admin"
set src in view(usr) //If it can be seen, it can be examined.
world << "11"
give_medal(M)
world << "12"


I think it's because M is null in this case. Since you are using set src in..., this verb is meant to be called by an admin on someone else.

You can do either this:

/mob/verb/grant_medal()
set name = "Grant Medal"
set category = "Admin"
set src in view(usr)
give_medal(src)


Or this: (Which is technically cleaner, but slower)

/mob/admin/verb/grant_medal()
set name = "Grant Medal"
set category = "Admin"
var/list/L = list()
for(var/mob/M in view(usr))
if(M.client)
L[M.name] = M
var/N = input(usr,"Award Medal","Who should receive a medal?") as text|null in L
if(N)
give_medal(L[N])
Attempted this, stuck on 155 again, it for some reason just doesn't.. Go on.. It's stupid.
In response to Raselor78
Is there a reason you are checking if user.medalslist is defined just afterthe 155 output?

It has been a long time since I last used BYOND so I do not know if DM would treat an list() as empty (FALSE) or not :S May want to check that out.

But if you added that line to check if the medal was already awarded or not, you may want to do this instead:
if(!(message in user.medalslist))
// OR
if(!(user.medalslist.Find(message)))
to check if it does NOT already exist in the list rather than "if(user && user.medalslist)".
Your medalslist must be null somehow... Could be caused by loading? If I were you, instead of having it do nothing if the medalslist is null, have it set the medalslist to a list.

if(!medalslist) medalslist=new/list
In response to GhostAnime
GhostAnime wrote:
Is there a reason you are checking if user.medalslist is defined just afterthe 155 output?

It has been a long time since I last used BYOND so I do not know if DM would treat an list() as empty (FALSE) or not :S May want to check that out.

But if you added that line to check if the medal was already awarded or not, you may want to do this instead:
if(!(message in user.medalslist))
// OR
if(!(user.medalslist.Find(message)))


It is because I'm checking for the list's existence, mostly to prevent null errors.