ID:141879
 
Code:
            verb/Use()
set src in usr.contents
if(usr.Working)
return
else
usr.Working=1
var/list/Buildlist=list()
for(var/obj/items/Alchemy/Potions/P)
if(!locate(P)in Buildlist)
Buildlist+=P
var/obj/C=input("Which potion would you like to make?")as null|anything in Buildlist
if(!C)
usr.Working=0
return
else


Problem description:
With this code, when i use the object, it builds the list correctly and everything works fine on it except for one thing. Theres a few potions that i have defined, but they dont show up in the list almost as if they don't exist. Does anyone know the reason for this, and if so how to fix it?
if(!locate(P)in List)

DM reads that code as (!locate(P))in List. Due to order of operations, !locate(P) occurs first. It looks for P, and if P exists, returns P, or true. The ! makes it opposite, false.

Then, it checks if "0" is in "List". Which doesn't make too much sense, does it?

Sooo:
if(!(locate(P)in List))

This checks if P is in List first, then the opposite of that.

By the way, you're checking for all the potions in the world, and adding them to "Buildlist" if they aren't already in it. The for() loop loops through all the potions in the world only once, so you don't have to check if it already added it since "Buildlist" is a new temporary list. I'm not sure if this is what you want.
In response to Kaiochao
Not only he doesn't have to do any check there at all, but locate() shouldn't be in the check even if it was needed. >_> What would be appropriate is the 'in' operator itself, not as part of locate() syntax (which is supposed to receive a type path, not object reference like you're doing, Godzooks).
In response to Kaiochao
Moving the ! operator had no effect on the loop.
for(var/obj/items/Alchemy/Potions/P)


There is your problem. It has no where to search (or it searches globally; I forget). So if there are no potions in the world, it won't find anything. What you want here is for(var/x in typesof(type path...)). Or, you could just say null|anything in typesof(type) in your input. It would really clean things up.
In response to Jeff8500
I've tried that, and the list only returns with the types, I'm trying to get it so it only has the names
In response to Jeff8500
It finds all the potions fine, except for 4 invisibility potions for some reason
In response to Godzooks
You need to be looking at a list of created objects to see the names. I suggest using one list containing all of them for the mobs to look at.

var/list/Potions=newlist(/obj/potion1,/obj/potion2,/obj/potion3)//Create a list of newly created potions.
mob/var/PotionMakingSkill=1

mob/verb/levelup()
PotionMakingSkill++
src<<"Leveled up to [PotionMakingSkill]!"
mob/verb/createpotion()
var/obj/o=input(src,"Choose!","Potions")as null|anything in Potions.Copy(1,PotionMakingSkill+1) //Only view potions you know how to make. With this basic level checking system, every level grants you a new potion.
if(o)
new o.type(src) //Change the reference o to a new object of the same type. Basically create a copy.
src<<"Created \a new [o]."
obj{potion1;potion2;potion3}

Untested. And sorry for the compact code, it's kind of a habit. I can read it, I'm hoping you can too :\
In response to Kaiochao
The whole reason of searching for potions is to prevent building huge lists that are ridiculous in length. Together, i have about 42 potions, and 37 of them come up, how the other 4 don't is beyond me.
In response to Godzooks
You could automatically create the list in world/New().
var/list/Potions
world/New()
..()
Potions=newlist(typesof(/obj/potions))
obj/potions
one
two
three

One list containing everything is much better than creating the list per person(as I used to long ago :P, not smart).

An alternative would be to create an associative list containing the types and the type path minus the "/obj/potion/" part, showing the name in the input().
In response to Kaiochao
that still does nothing.

Theres only 4 potions that don't come up in the list! how hard can it be?
In response to Godzooks
How are you defining your potion types?
In response to Kaiochao
here's exactly how my system works..
var/list/Buildlist //According to what that one guy said
world/New()
..()
Buildlist=newslist(typesof(/obj/items/Potionmaking/Potions))

obj/items
Potionmaking
Potions
icon='Potionmaking.dmi'
Health Potion
icon_state="Health"
Magic_Potion
icon_state="Magic"
//the list goes on to like 41 potions
Tools
Pestle
icon_state="Pestle"
verb/use()
set src in usr.contents
if(usr.Working)
return
var/obj/C=input("What potion would you like to make?")as null|anything in Buildlist


but when i run it, I get nothing. And if i use my other concept of coding this, i only get 37/41 potions
In response to Godzooks
The 4 that don't show up, are they tabbed correctly? :|

Edit: By the way, it's newlist(), not newslist(). And you can have newlist() when your defining the variable instead of putting it in world/New().
In response to Kaiochao
yes, all the potion code is 100% correct, there are no errors.
In response to Godzooks
If there are no errors, there shouldn't be errors.
In response to Kaiochao
Like I said. With the potion code. I didn't say anything about the code to make potions
In response to Godzooks
var/list/Buildlist=list()
world/New()
for(var/t in typesof(/obj/items/Potionmaking/Potions))Buildlist+=new t
obj/items
Potionmaking
Potions
Health_Potion
Magic_Potion
Tools
Pestle
verb/use()
set src in usr
if(usr.Working)return
var/obj/C=input("What potion would you like to make?","Potion Making")in Buildlist
//etc.


I thought newlist() took lists as an argument, silly me. Above code works.
In response to Kaiochao
Sweet! Thanks it works
In response to Godzooks
Sorry it took so long for me to notice, hehe.
Page: 1 2