ID:1673018
 
(See the best response by Kaiochao.)
Code:


Problem description: So for a random cloth generater lets say I have clothing in a clothing folder with a bunch of different icon files for each different pair. I want it make a list of icons from this folder. Is this even possible?

So my list would contain ('shirt.dmi','t-shirt.dmi,...) Something like that. If not dont worry ill do something different im just curious if that is possible


or if theres a way to do 'shirt[i].dmi' that would be nice too
There's the iconstates() proc which I use for a number of things. It makes a list of iconstates with in an icon.

But if you have everything seperated into icon files you can use the proc that does the same to directories, it is the flist() proc.
Best response
flist() doesn't work with files in the rsc, only with files on the host computer. If you want to use flist(), you'll have to distribute your .dmi files along with the host files.

Or, you could make a list of icon files and pick from it. Using flist() and text2file() you can generate with code a code file containing a list of all files in a folder at compile-time.
In response to Jittai
how does iconstates() work. how do you add to it. didnt get a good example on the reference
var/list/states = icon_states(icon)

It returns a list of text strings of every state in the icon file.
oh okay thank you, those are the few tools i still havent used. From both jittai and kaiochao thank you, this will help me with an idea.
In response to Kaiochao
also how would you make it at compile time.
mob
New()

something like that, or would it be, before a new function.
In response to Anthonytyran
You could use pick() to grab a random icon state from the list returned by icon_states().
If you're going to be generating items from this list, running it once would be ideal. You could store the list into a global list during world/New().
In response to Jittai
oh okay thak you, my coding seems to be working quite well besides one factor. Once i get the list how do i make it equal to the icon. because src.icon=list[1](this is the list of the icon files) doesnt work
neither did i think it would, but what am i missing
This is what I mean: http://puu.sh/blNqK/74cc52f1e3.zip

Extract that and copy/paste your icon folder into the icon loader's folder.
Set the "folder" variable to the name of your icon folder.
Then just run it and hit the Load verb.

A new code file should appear called "loaded icons.dm" containing a list that looks like this:
var icons[] = list(
"some icon" = 'some icon.dmi',
"other icon" = 'other icon.dmi',
// etc.


Now, you can access your icons dynamically. Example:
// this list was generated by the icon loader
// you don't have to type this out at all
var icons[] = list(
"icon 1" = 'icon 1.dmi',
"icon 2" = 'icon 2.dmi',
"icon 3" = 'icon 3.dmi',
"other icon" = 'other icon.dmi',
"some icon" = 'some icon.dmi'
)

// and this is how you access the icons in the list
mob/Login()
..()
icon = icons["icon [rand(1, 3)]"]
oh okay this reminds me of hashes in other languages, or am i mistaken. Hashes or a dictionary one of the two. thank you !!!
In response to Anthonytyran
Dictionary, Map, JSON. Associative lists in DM are just Keys mapped to Values. list(Key1 = Value1, Key2 = Value2, etc.)

All lists are associative lists, where Value defaults to null, and duplicate keys are allowed.