ID:145303
 
Code:
mob/verb/Highscores()
sort_players()
src << "<b>Highest level players logged onto [world.name]:</b>/n"
for(var/mob/player/P in plist)
src << "([P.key])[P.ChopSkill] [P.FishSkill] [P.CookSkill]"

mob/proc/sort_players(var/mob/player/P in plist)
var/level = P.ChopSkill+P.FishSkill+P.CookSkill
var/i,j,k
for(i=1, i<plist.len, ++i)
k = i
var/mob/Mk = plist[k]
for(j=i+1, j<=plist.len, ++j)
var/mob/Mj = plist[j]
if(Mj.level > Mk.level)
Mk = Mj; k = j
if(k != i) plist.Swap(i, k)


Problem description:
It's telling me there is a problem with if(Mj.level > Mk.level)
Claiming they are undefined :(

my first thought is that the level var is not a var associated with mob/

did you do something like
mob/var/thisIsAcharThatCanLevel/level

Cuz if that's the case, your statement:
var/mob/Mk = plist[k]

should be
var/mob/thisIsAcharThatCanLevel/Mk = plist[k]
In response to Jerico2day
mob/proc/sort_players(var/mob/player/P in plist)
var/mob/player/level = P.ChopSkill+P.FishSkill+P.CookSkill
var/i,j,k
for(i=1, i<plist.len, ++i)
k = i
var/mob/player/Mk = plist[k]
for(j=i+1, j<=plist.len, ++j)
var/mob/player/Mj = plist[j]
if(Mj.level > Mk.level)
Mk = Mj; k = j
if(k != i) plist.Swap(i, k)

Same errors now.
In response to Derekjeterisgod
You lose, game over!

To try again, don't make a variable called level of type /mob/player.
In response to PirateHead
I replaced all /mob/player with /mob/score and I'm still getting the same errors....
In response to Derekjeterisgod
You lose, game over!

To try again, don't make a variable called level of type /mob/score.
In response to PirateHead
Your no help... Anyways I'm going to use Dantoms hublib
In response to PirateHead
PirateHead wrote:
You lose, game over!

To try again, don't make a variable called level of type /mob/score.

You lose, game over!

You failed to try and understand what the developer was attempting when he wrote the code, or to provide help that was at a level the developer could understand.


To Derekjeter (sorry man, a Redsox fan :P )
I think you misunderstand the scope of variables, and how that is effected by where they are defined. Because the variable "level" is defined in a proc, its scope (where it can be used) is only in that proc. That variable does not belong to /mob, it isn't associated with any object, and exists only in that proc. To make a variable that is associated with every /mob, define it directly in /mob/var.

mob/verb/Highscores()
sort_players()
src << "<b>Highest level players logged onto [world.name]:</b>/n"
for(var/mob/player/P in plist)
src << "([P.key])[P.ChopSkill] [P.FishSkill] [P.CookSkill]"

mob/proc/sort_players(var/mob/player/P in plist)
/*Why is sort_players asking for an argument?
Why arn't you supplying that argument in Highscores?*/

var/level = P.ChopSkill+P.FishSkill+P.CookSkill
//Do you want this variable to be associated with the type /mob?
var/i,j,k
for(i=1, i<plist.len, ++i)
k = i
var/mob/Mk = plist[k]
for(j=i+1, j<=plist.len, ++j)
var/mob/Mj = plist[j]
if(Mj.level > Mk.level)
/*Mj and Mk are of type /mob, which does not
have the variable 'level' associated with it.*/

Mk = Mj; k = j
if(k != i) plist.Swap(i, k)
/*Perhaps I'm just not seeing another part of your
program (where you've defined plist, etc.) but I
don't understand the function of k, or why it is
being swaped. It's always a good idea to give your
variables names that describe why they exist.*/


The two things I'd do to improve this snippit, are to give the /mob type a "level" variable, and to include another loop in sort_players() which assigns a level to each mob. I think that may be what you were trying to do with that argument.

mob
var/level = 0
/* /mob now has a field called "level." */
proc/sort_players()
for(var/mob/player/P in plist){
P.level = P.ChopSkill+P.FishSkill+P.CookSkill
var/i,j,k
for(i=1, i<plist.len, ++i)
k = i
var/mob/Mk = plist[k]
for(j=i+1, j<=plist.len, ++j)
var/mob/Mj = plist[j]
if(Mj.level > Mk.level)
Mk = Mj; k = j
if(k != i) plist.Swap(i, k)

If I understood the function of i, j, and k, I might have been able to simplify those loops.

If you don't want mobs to always carry around a level var, you could make an associative list in sort_players().
proc/sort_players()
var/list/player_levels[0]
for(var/mob/player/P in plist){
/*The object P becomes an index of player_levels[].*/
player_levels[P] = P.ChopSkill+P.FishSkill+P.CookSkill
var/i,j,k
for(i=1, i<plist.len, ++i)
k = i
var/mob/Mk = plist[k]
for(j=i+1, j<=plist.len, ++j)
var/mob/Mj = plist[j]
/*The objects Mj and Mk (the same one's we added
above) are used as indexes of player_levels[] to
access their associated level value.*/

if(player_levels[Mj] > player_levels[Mk])
Mk = Mj; k = j
if(k != i) plist.Swap(i, k)