ID:142298
 
Code:
mob/*admin*/
verb
Additem()
var/Objs
for(var/S in typesof(/obj/)-/obj/)
Objs += list(S)
var/obj/Ob = input("Choose an item","Additem") in Objs
Ob.Move(src)


Problem description:
Desired Effect: Player chooses an item from the list of objs and it adds to the player's contents
The list shows up, but the obj doesn't add and i get this error:

runtime error: Cannot execute null.Move().
proc name: Additem (/mob/verb/Additem)
usr: KingCold999 (/mob/player)
src: KingCold999 (/mob/player)
call stack:
KingCold999 (/mob/player): Additem()

if(Ob)
Ob.Move(src)
In response to Andre-g1
Andre-g1 wrote:
> if(Ob)
> Ob.Move(src)


still have the same error

is there any other way of making this verb?
You were making a list of types of objs (not actual objects), and then you were setting an obj to equal a type instead of a real obj.
mob/*admin*/
verb
Additem()
var/list/Objs=typesof(/obj)
Objs.Remove(/obj)
var/T=input(src,"Choose an item.","Additem") as anything|null in Objs
if(!T) return
var/obj/O = new T
O.Move(src)

Also, instead of letting them select from types, you may have wanted them to see the actual names of the objects, like so:
mob/*admin*/
verb
Additem()
var/list/Objs=typesof(/obj)
Objs.Remove(/obj)
var/list/realobjs=list()
for(var/T in Objs)
realobjs+= new T
var/obj/O=input(src,"Choose an item.","Additem") as obj|null in realobjs
if(!O) return
O.Move(src)
In response to KingCold999
You are making the person pick a path, which is not created yet.

Right after the input, Ob is a path, so you are saying something like /X.Move(Y)

Replace Ob.Move(src) with "new Ob(src)"
In response to GhostAnime
GhostAnime wrote:
You are making the person pick a path, which is not created yet.

Right after the input, Ob is a path, so you are saying something like /X.Move(Y)

Replace Ob.Move(src) with "new Ob(src)"

Thankyou very much! This worked.

working code with comments(if anyone needs/wants this for admins)
mob/admin //can edit for GM/PM/OWNER/CoOwner/other
verb
Additem()
var/Objs //creates a var to store the obj list in
for(var/S in typesof(/obj/)) //gets all of the objs in the source /obj/ (can change to /obj/item for items only)
Objs += list(S) //adds to list
var/obj/Ob = input("Choose an item","Additem") in Objs //player/admin chooses an item
new Ob(src) //creates the obj
In response to KingCold999
XD, I feel ignored.
With my way, they are given a cancel button...
Anyways here's the cancel button part if you wanted it:
            var/obj/Ob = input("Choose an item","Additem") as null|anything in Objs //player/admin chooses an item + cancel button
if(!Ob) return //ends if cancelled
new Ob(src) //creates the obj
In response to Naokohiro
Srry bout that, i saw his post first XD
btw thanks for the cancel button! Works great!
In response to KingCold999
You should try Topic View in Preferences, so you can see the order of who posted first.
And, it's no problem. :D
In response to KingCold999
        Additem()
var/Objs //creates a var to store the obj list in
for(var/S in typesof(/obj/)) //gets all of the objs in the source /obj/ (can change to /obj/item for items only)
Objs += list(S) //adds to list

That works, but I'd say it's a bit of a strange (and maybe less efficient?) way to do it.

        Additem()
var/list/Objs=new //Creates an actual list
for(var/S in typesof(/obj/))
Objs += S //adds to list, but doesn't call the list() proc every single time
In response to Nickr5
Or...
var/list/Objs = typesof(/obj)-/obj
since typesof() returns the value as a list...

And since the list is only being used once, we can do:
        Additem()
var/obj/Ob = input(src,"?","!") as null|anything in (typesof(/obj)-/obj)
if(!Ob)return
new Ob(src) // creates a new instance of Ob's path in src
In response to GhostAnime
That appears to be the most efficient.
In response to Naokohiro
Lists-wise, using - does something different than the "shorthand" form of -=, and is actually less efficient. It is unneeded for cases such as this, and -= should be used instead (or Remove(), but that's slower and betrays the purpose).