ID:179123
 
The goal here, it's supposed to pick a random item from a list and create a new version of it. It gives me errors if I try though.


mob/proc/GetItems()
var/list/Items = newlist(\
/obj/objects/items/doodad,\
/obj/objects/items/monkeylover,\
/obj/objects/items/squeegee,\
/obj/objects/items/chalk,\
/obj/objects/items/sputnik,\
/obj/objects/items/sputterwolly,\
/obj/objects/items/thumper,\
/obj/objects/items/dingdong,\
)
var/obj/random = pick(Items)
return random

mob/proc/FindItem()
var/obj/O = GetItems()
new O.type (src.loc)


Okay, so, someone instruct me on what I'm doing wrong?
What errors are you getting?
I don't offhand see anything wrong with that code, but using newlist is a major waste of resources. Its better to use a list of paths, pick one and create it. Otherwise, everytime FindItem is called, 9 objects are created when only one is used. I'd change the code to this:

<FONT COLOR=silver>
mob/proc/GetItems()
> var/list/Items = list(\
> /obj/objects/items/doodad,\
> /obj/objects/items/monkeylover,\
> /obj/objects/items/squeegee,\
> /obj/objects/items/chalk,\
> /obj/objects/items/sputnik,\
> /obj/objects/items/sputterwolly,\
> /obj/objects/items/thumper,\
> /obj/objects/items/dingdong,\
> )
> var/random = pick(Items)
> return random
>
> mob/proc/FindItem()
> var/O = GetItems()
> new O(src.loc)
</FONT>


That probably doesn't fix your problem, though, unless your problem is unrelated to the code you posted.

-AbyssDragon
In response to Nadrew
runtime error: Cannot read null.type.
proc name: SearchItems (/mob/proc/SearchItems)
source file: items.dm,28
usr: Foomer (/mob/pc)
src: Foomer (/mob/pc)
call stack:
Foomer (/mob/pc): SearchItems(/list (/list))
ScanOptions(Foomer (/mob/pc), /list (/list))
ScanInput(Foomer (/mob/pc), "")
In response to Foomer
Foomer wrote:
runtime error: Cannot read null.type.
proc name: SearchItems (/mob/proc/SearchItems)
source file: items.dm,28
usr: Foomer (/mob/pc)
src: Foomer (/mob/pc)
call stack:
Foomer (/mob/pc): SearchItems(/list (/list))
ScanOptions(Foomer (/mob/pc), /list (/list))
ScanInput(Foomer (/mob/pc), "")

SearchItems() doesn't appear to be in the code you were using, unless you renamed FindItem(). I do see one problem in GetItems() that I think could cause a null.type problem: You have a comma before the closing parenthesis, which DM might be interpreting as another null entry at the end of the list. But, unless the failure is happening in GetItems(), I would expect any problems from that to be intermittent since they would only happen when the null item was picked.

Lummox JR
In response to Lummox JR
That doesn't help the problem, apparently. And FindItems() is just a short version of the 40 lines or so in SearchItems(), but that's all irrelevant code.

Anyway, I figured out something that might be causing it.

Okay, I got it. Nevermind (thanks for the help).