Bad Score Update in Developer Help
|
|
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 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?
|
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))