ID:149007
 
The following code has a problem that I can't seem to fix, due to it being some odd errors.
proc
SpaceShip()
var/mob/B // Error
var/list/scores // Error
var/list/scorers // Error
var/hiscore = max(scores) // Error
var/pos // Error
for(B in world)
if(B.client)
scores += B.worldscore
scorers += B.name
continue
else
continue
pos = scores.Find(hiscore) // Error
world << "[scorers[pos]] has won the game with [hiscore] points." // Error


The errors are (follow only the errors, not the warnings)

loading Inf.dme
f:\BYOND\users\MASTER\lib\spuzzum\s_admin\s_admin2.dm:440:vi sibility:warning: visibility is being phased out; use invisibility
space.dm:3:error:B :invalid proc definition
space.dm:4:error:scores :invalid proc definition
space.dm:5:error:scorers :invalid proc definition
space.dm:6:error:hiscore :invalid proc definition
space.dm:7:error:pos :invalid proc definition
space.dm:15:error:= :invalid proc definition
space.dm:16:error:<< :invalid proc definition
f:\BYOND\users\MASTER\lib\spuzzum\s_admin\s_admin2.dm:440:sr c.visibility:warning: visibility is being phased out; use invisibility
f:\BYOND\users\MASTER\lib\spuzzum\s_admin\s_admin2.dm:998:if :warning: if statement has no effect
f:\BYOND\users\MASTER\lib\spuzzum\s_admin\s_admin2.dm:999:if :warning: if statement has no effect

Inf.dmb - 7 errors, 4 warnings (double-click on an error to jump to it)
It looks like you forgot to indent the vars in the body of your SpaceShip() proc. The compiler is reading your var declarations as if they are procs and complaining because they don't work that way. Try putting another tab in front of your vars. The same goes for the last two lines.
Drafonis wrote:
The following code has a problem that I can't seem to fix, due to it being some odd errors.
proc
SpaceShip()

space.dm:3:error:B :invalid proc definition

You don't actually have anything listed under this proc. It goes right on to the vars, indeded at the same level. It's like you're saying proc/SpaceShip() and then proc/var/mob/B.
    var/mob/B // Error
var/list/scores // Error
var/list/scorers // Error
var/hiscore = max(scores) // Error
var/pos // Error

I assume all these were meant to be indented further.
That max(scores) is going to be useless to you, too, since scores isn't defined at this point (it's null), and max(list) is an invalid format; that'd have to be max(arglist(list)) to do anything, and I'm not sure arglist() is supported by max().

If what you're trying to do here is automatically calculate hiscore everytime the scores list changes, it's not going to work. You have to go through and find it yourself every time.
        for(B in world)
if(B.client)
scores += B.worldscore
scorers += B.name
continue
else
continue
pos = scores.Find(hiscore) // Error
world << "[scorers[pos]] has won the game with [hiscore] points." // Error


Those last two lines are indented at the same level as the vars--that is, the wrong level. So it's like saying proc/pos = scores.Find(hiscore).

Using a double list to keep track of scores is probably a very bad idea. In fact you don't even need a list to find the high score here:
proc
SpaceShip()
var/mob/B
var/mob/winner
for(B in world)
if(B.client)
if(!winner || B.worldscore>winner.worldscore) winner=B
world << "[B.name] has won the game with [hiscore] point\s."

This doesn't account for ties. A way to account for ties would be this:
proc
SpaceShip()
var/mob/B
var/list/winners
var/hiscore
for(B in world)
if(B.client)
if(!winners || B.worldscore>hiscore)
winners=list()
hiscore=B.worldscore
else if(B.worldscore<hiscore) continue
winners+=B
if(!winners)
world << "Nobody won."
else if(winners.len==1)
B=winners[1]
world << "[B.name] has won the game with [hiscore] point\s."
else
world << "[MobListToText(winners)] have tied for the high score of [hiscore] point\s."

// a handy generic proc for printing a list of mob names
// other good choices for conj might be "or" or "then".
proc/MobListToText(list/L,conj="and")
var/t
var/mob/M
if(!L || !L.len) return ""
if(L.len==1)
M=L[1]
return M.name
if(L.len==2)
M=L[1]
t="[M.name] "
else
t=""
for(var/i=1,i<L.len,++i)
M=L[i]
t+="[M.name], "
M=L[L.len]
t+="[conj] [M.name]"

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Drafonis wrote:
The following code has a problem that I can't seem to fix, due to it being some odd errors.
proc
> SpaceShip()

space.dm:3:error:B :invalid proc definition

You don't actually have anything listed under this proc. It goes right on to the vars, indeded at the same level. It's like you're saying proc/SpaceShip() and then proc/var/mob/B.
    var/mob/B // Error
> var/list/scores // Error
> var/list/scorers // Error
> var/hiscore = max(scores) // Error
> var/pos // Error

I assume all these were meant to be indented further.
That max(scores) is going to be useless to you, too, since scores isn't defined at this point (it's null), and max(list) is an invalid format; that'd have to be max(arglist(list)) to do anything, and I'm not sure arglist() is supported by max().

If what you're trying to do here is automatically calculate hiscore everytime the scores list changes, it's not going to work. You have to go through and find it yourself every time.
        for(B in world)
> if(B.client)
> scores += B.worldscore
> scorers += B.name
> continue
> else
> continue
> pos = scores.Find(hiscore) // Error
> world << "[scorers[pos]] has won the game with [hiscore] points." // Error

Those last two lines are indented at the same level as the vars--that is, the wrong level. So it's like saying proc/pos = scores.Find(hiscore).

Using a double list to keep track of scores is probably a very bad idea. In fact you don't even need a list to find the high score here:
proc
> SpaceShip()
> var/mob/B
> var/mob/winner
> for(B in world)
> if(B.client)
> if(!winner || B.worldscore>winner.worldscore) winner=B
> world << "[B.name] has won the game with [hiscore] point\s."

This doesn't account for ties. A way to account for ties would be this:
proc
> SpaceShip()
> var/mob/B
> var/list/winners
> var/hiscore
> for(B in world)
> if(B.client)
> if(!winners || B.worldscore>hiscore)
> winners=list()
> hiscore=B.worldscore
> else if(B.worldscore<hiscore) continue
> winners+=B
> if(!winners)
> world << "Nobody won."
> else if(winners.len==1)
> B=winners[1]
> world << "[B.name] has won the game with [hiscore] point\s."
> else
> world << "[MobListToText(winners)] have tied for the high score of [hiscore] point\s."
>
> // a handy generic proc for printing a list of mob names
> // other good choices for conj might be "or" or "then".
> proc/MobListToText(list/L,conj="and")
> var/t
> var/mob/M
> if(!L || !L.len) return ""
> if(L.len==1)
> M=L[1]
> return M.name
> if(L.len==2)
> M=L[1]
> t="[M.name] "
> else
> t=""
> for(var/i=1,i<L.len,++i)
> M=L[i]
> t+="[M.name], "
> M=L[L.len]
> t+="[conj] [M.name]"

Lummox JR

Thank you. I am definitely including you in credits.