ID:162116
 
Hi, I am having a small problem with building lists. Could someone help me please? Heres the code.

    Anvil
icon_state="Anvil"
DblClick()
if(get_dist(src,usr)<2)
var/HA=/obj/items/Blacksmithing/Other/Hammer
if(locate(HA)in usr)
switch(input("What type would you like to smith?")in list("Armor","Weapons","Shields","Cancel"))
if("Armor")
var/list/Armorlist=list()
for(var/O as anything in typesof(/obj/items/Blacksmithing/Armor))
if(!locate(O) in Armorlist)
Armorlist+=O
var/T=input("Which piece would you like to smith?","Anvil")as null|anything in Armorlist
if(!T)
return
else


The problem is that the directories show up in the list. Is it possible to make it so the name shows up, and not the directory?
var/list/smithingtypes = list(
"Armor"=/obj/items/Blacksmithing/Armor,
"Weapons"=/obj/items/Blacksmithing/Weapon,
"Shields"=/obj/items/Blacksmithing/Shield
)
//get the name of what you want to smith
var/input = input("What would you like to smith?") in smithingtypes
//get the associated value (the type path)
var/selection = smithingtypes[input]

//generate the list of things we can smith
var/list/smithlist = list()
for(var/T in typesof(selection))
//don't select anything with any subtypes
if(typesof(T).len == 1)
//create a new instance of that object
var/obj/items/Blacksmithing/O = new T()
smithlist += O

//now you can go on to select an object from smithlist
//note that the object is already created, so you won't need to make a new one
//the unused objects should be deleted by the garbage collector when the proc ends
In response to Garthor
all you needed to say was instead of adding object O to the list, make that O.name

but once u do so, u need to cross-reference this back to the object with for(duh duh duh) if(name = selected) then var/object = O, then add to inventory after its moved back to the object itself, instead of just the name.
In response to Superbike32
Or, you know, you could just do what I did and have something that makes sense and works.
In response to Garthor
mine works as well, and giving an alternative to a code isnt going to kill anyone. he could possibly not know what your code does, or could possibly want to do it an alternative way, and the choice is always with the person making the game.

It is best if he does it his way, and he to understand it, rather then someone else posting code that he doesnt understand, in which then he would not be able to use something similar to that in the feature, and would keep coming back for answers.

Like i do because i cant use anything i learn because its some experts code, and i cant change it up at all or else i get errors.

Nobody forces anyone to play their games, and if u have a problem with the game, u dont gotta play it, so giving them answers they understand so they dont gotta ask questions all the time is essential to helping people becoming better at coding on byond.
In response to Superbike32
Superbike32 wrote:
mine works as well, and giving an alternative to a code isnt going to kill anyone. he could possibly not know what your code does, or could possibly want to do it an alternative way, and the choice is always with the person making the game.

*I* don't even know what the hell your "code" does. All I know is that it's blatantly wrong, because you're using a for() loop to do... something, but a for() loop does NOT belong here. And yes, providing WRONG "alternatives" is harmful.

It is best if he does it his way, and he to understand it, rather then someone else posting code that he doesnt understand, in which then he would not be able to use something similar to that in the feature, and would keep coming back for answers.

Like you?

Like i do because i cant use anything i learn because its some experts code, and i cant change it up at all or else i get errors.

That's a problem on your end for using code you don't understand.

Nobody forces anyone to play their games, and if u have a problem with the game, u dont gotta play it, so giving them answers they understand so they dont gotta ask questions all the time is essential to helping people becoming better at coding on byond.

Once again, your answer made about as much sense as anything else you write. Specifically: next to none. You're not helping anybody by providing such "advice."
In response to Garthor
my advice is to give out code people understand so they dont have to keep asking questions all the time.

the reason i have so blatantly kept asking about my first post about lists is because i am not going to use urs because i really dont understand how it works, and would not be able to change it up for my use.
In response to Superbike32
Don't drift off topic, and don't try to provide advice until you know what you're doing.
In response to Garthor
i could give code xamples, and they work on mine, as i have it working on mine. whether he gets what im trying to say or not is really how much hes trying to get it to work.

good advice and bad advice to you seems to not be based on anything but whether its your code or not, i have heard no reasons why my code is worse, or what kind of effects, such as lag//ect.... that it would have on the actual game.

So unless there is any proof that some way is actually worse, i would keep posting the same "bad advice" and i post ways that seem to be easier for me.

That is why we r "begginners" in your eyes, and yall r "experts" but the truth is, that maybe yall could do stuff, and in less code, or in a way that makes more sense to you, and maybe even faster, but we can do the exact same things, but not coding it in the same fashion as yall.

If i had proof of the effects these codes im posting would have on the game, such as lag//ect... then i would stop posting such advice on said forums.

Until then, i have no reason to think that my code might actually function worse than urs and create lag//ect...
In response to Superbike32
Any code written by you is going to be far worse and far less efficient that Garthor's because you are nowhere close, not even by an extremely liberal longshot, to being good enough to show people how to program. You've already been banned once before for a) giving out bad advice and b) thinking you actually know anything about programming efficiently when you reply haughtily and arrogantly as you are now. I'm assuming that you want the mods to ban you again?