ID:138866
 
Code:
        GameOver()
src << output("Game over! Final Score: [src.Score].","Chat")
if(Score == 63)
switch(Mode)
if("Casual")
world.SetMedal("Ace of the Board",src)
if("Classic")
world.SetMedal("Experienced Traveler",src)
switch(Mode)
if("Casual")
var/result = world.GetScores(src.key,"Score")
if(isnull(result))
var/list/params = list("Score"="[src.Score]")
world.SetScores("[src.key]",list2params(params))
else // Got here
var/X = text2num(result)
src << output("[result]","Chat")
src << output("[X]: It works","Chat")
if(X < src.Score)
var/list/params = list("Score"="[src.Score]")
world.SetScores("[src.key]",list2params(params))


Problem description:
Okay, so Masterdarwin noted that my scores updates incorrectly in The Knight. I've tried fixing it, and this is what I came up with. It doesn't work. My debugging lines are showing, only the second one "[X]" is shown as null (or just lack of text?) What am I doing wrong?
If world.GetScores() returns null, then the hub couldn't be reached. Otherwise it returns a parameter string.

First, you need to check that result is not null (give a warning or something if it is). If it's not, then run params2list() on result. Now you can check if the key "Score" has a value and if it's less than the current score. Then if the score should be updated, use SetScores().

I would do it like this:
        GameOver()
src << output("Game over! Final Score: [src.Score].","Chat")
if(Score == 63)
switch(Mode)
if("Casual")
world.SetMedal("Ace of the Board",src)
if("Classic")
world.SetMedal("Experienced Traveler",src)
switch(Mode)
if("Casual")
var/result = world.GetScores(src.key,"Score")
if(result == null)
src << output("WARNING! Could not contact hub to set score!","Chat")
else
var/list/params = params2list(result)
if(!params["Score"] || text2num(params["Score"])<src.Score)
params = list("Score"="[src.Score]")
world.SetScores(src.key,list2params(params))
In response to DarkCampainger (#1)
So the issue with my stuff was that I assumed that I would get a text string rather than a list of parameters? Okidokes. I'll do a little studying of this after I finish my calc homework. Thanks for helping.
In response to Lugia319 (#2)
Lugia319 wrote:
So the issue with my stuff was that I assumed that I would get a text string rather than a list of parameters? Okidokes. I'll do a little studying of this after I finish my calc homework. Thanks for helping.

Exactly. 'result' should be set to something like "Score=34" by world.GetScores(), so you have to use params2list() to access just the 34 (which will be in text form, as you knew).

Also, result being null didn't mean that no score was present, but rather that the hub couldn't be contacted.
In response to DarkCampainger (#3)
Alrighty. Thanks a bunch!