ID:178953
 
Is there a way to create a conditional list?
Like I have a list. But then I only want things to show up in the list if their quanity is greater than 0. Otherwise you'll have a blank list if you have nothing.

LJR
The simple answer is: only put things in the list if they have a quantity. But I don't think that's exactly what you're asking. Is this it?

proc/parselist(list/l)
var/list/parsedlist = list()
for (var/i in l)
if (l[i]) parsedlist[i] = l[i]
return parsedlist


With this proc, if you refer to a list like so:
Stat()
if (statpanel("Skills"))
parsedlist(src.skills)

it will display only items in the skills lists associated with a value. Again:

verb/practice(skill in parsedlist(src.skills))

will allow you to practice any skill in your list, as long as you already have a rating in it.
Not that I know of, the easiest thing to do would be to just not add anything to the list that is <= 0. Or you could just remove them before using the list:

var/list/L = list(0,3,2,1,0,2,0)
while(L.Find(0))
L -= 0
In response to Lesbian Assassin
var/tmp/list/jet
if (colonist > 0) jet += list("Colonist")

Well this is a snippet of my list. Its a tmp list to only be used for selection and will be null'ed after each use.
This is how I have it now to add the selection of Colonist if u have more than 0

This is suppose to be a list selection list and now that I look at it do I just need to do like += ("Colonist")??

LJR
In response to LordJR
If you only have one item in the list what do you think happens?
In response to Nadrew
Don't answer a question with a question silly. I know already that it skips the list and does whats left if its the only thing to do in the list. My worry is am I adding ("Text Selections") to the list???

LJR
In response to LordJR
You are adding text to the list. What of it? I think you need to do some serious reading up on lists...
In response to Lesbian Assassin
I have the Blue Book right reading..reading.. who's got the reading??? Its just I'm doing it a way I havent' done before so I just need clarification. Also the fact I'm at work right now and have no way of compiling to test this. Otherwise I would not ask here.

LJR
In response to LordJR
Then wait until you can test it.
In response to Nadrew
Why don't u stuff it! :P
BLAH!

LJR
In response to LordJR
Don't make me go and stop helping you..
In response to Nadrew
WHAT!?? Helping me?? In this thread you've contributed nothing to my knowledge base. :P

LJR
In response to LordJR
Who said anything about this thread?
In response to Nadrew
I did! And this is my last post on it. BLAH! :P

Now back to programming....

LJR
In response to LordJR
LordJR wrote:
var/tmp/list/jet
if (colonist > 0) jet += list("Colonist")

Well this is a snippet of my list. Its a tmp list to only be used for selection and will be null'ed after each use.
This is how I have it now to add the selection of Colonist if u have more than 0

This is suppose to be a list selection list and now that I look at it do I just need to do like += ("Colonist")??

The first thing I'd do is make sure jet is initialized to list(). Then whenever you add text, just add the text (like +="Colonist") and don't worry about list("Colonist"). Both forms will work, but there's no need to make a new list only to destroy it again.

It sounds to me as if the vars you're trying to display really would be better off in a list already. But if they're not, you could try this:
var/tmp/list/jet=list()
var/list/varnames=list("Colonist","Food","Blue Things",...)
for(var/vn in varnames)
// ckey(vn) makes "Colonist" into "colonist",
// "Blue Things" into "bluethings", etc.
var/n=vars[ckey(vn)]
if(n>0) jet+=vn

This is a hacky solution that requires all your var names to be equal to the ckey() version of how they're displayed in the jet list. However, it's not a bad place to start. Alternatively, you could make varnames an associative list like this:
var/list/varnames=list("colonist"="Colonist",
"food"="Food",
"blue"="Blue Things")
for(var/vn in varnames)
var/n=vars[vn]
if(n>0) jet+=varnames[vn]

And in this example, the elements of varnames are the actual variable names, associated with the descriptive name you want to display.

Lummox JR
In response to Nadrew
Nadrew, your one line posts are never helpful.
In response to LordJR
Shouldn't you be, oh I don't know, working at work?