ID:179705
 
Ok, hate to bug you guys with this, but I really dont understand lists =(

Anyway, what I'm trying to do is make it so a GM can create a new campaign, or choose one of his/her old ones. Every time a GM makes a new campaign, it's (supposedly) stored in a list named lgames. That being said, here's my code for the New_Game & Choose_Game verbs I have


New_Game()
  set_desc = "() Begin a new game/campaign"
  set category = "Session"

  var/cname = input(src, "Set Campaign", "Set Game") as text
  lgames += cname
  campaign = cname;


Choose_Game()
  set desc = "() Pick a game to play"
  set category = "Session"

  campaign = input(src, "Which Game?", "Choose Game") in lgames


The problem is that the campaign doesnt seem to get added to the list lgames. Everything else works fine, but lgames stays blank for some reason. Any ideas on what I'm doing wrong?
Where are you defining the list lgames? That's not in your code.
Bah, fixed my own problem, heh. It was what you were probably suspecting Skysaw, I didnt intialize correctly. But, all better =P Next problem (I'm full of em, neh?)

How would I go about showing only mobs in the world on a stat panel? Basically world.contents, but only the mobs?
I'm sure it involves those dreaded lists, but like I already said, I'm clueless with them (and not for lack of trying, btw). Any help would be appreciated. Code examples are not necessary, but would probably help my slow, numb, brain to absorb it =P Thanks in advance
In response to sapphiremagus (#2)
You would have to use a for loop to check for all the mobs in the world here's one way of doing it:

mob
Stat()
..()
statpanel("Players")
for(var/mob/M in world)
if(M.client)
stat("[M]")
In response to Nadrew (#3)
Damn . . . . .you make that look so simple, lol. Thanks Nadrew (*sets off to study and customize*)
In response to sapphiremagus (#4)
It is simple =P
In response to Nadrew (#3)
Nadrew wrote:
You would have to use a for loop to check for all the mobs in the world here's one way of doing it:

> mob
> Stat()
> ..()
> statpanel("Players")
> for(var/mob/M in world)
> if(M.client)
> stat("[M]")
>

That should work, and if the game stays small, it is perfectly adequate. I will point out, however, that with a lot of players/mobs, this could bog down the server quite a bit. Stat() is called pretty frequently for each player, and counting all of anything in the world has a bit of overhead associated with it.

If you want it lean and mean, you've gotta use a global list. The code would be a bit more involved though, adding to the list with each mob creation, and deleting from the list when the mob is deleted. That might be an annoyance from a programming standpoint, but being able to just use:
statpanel("Players", players)

or

statpanel("Creatures", creatures)

would be nice, wouldn't it? ;-)

Trust me, learning the ins and outs of lists will vastly improve how much you can pack into your game before it starts choking.

/mob/skysaw