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
ID:178953
![]() Mar 13 2002, 10:03 pm
|
|
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 |
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 |
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 |
You are adding text to the list. What of it? I think you need to do some serious reading up on lists...
|
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 |
LordJR wrote:
var/tmp/list/jet 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() 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", And in this example, the elements of varnames are the actual variable names, associated with the descriptive name you want to display. Lummox JR |
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.