ID:2258784
 
(See the best response by Kaiochao.)
Code:
obj
Ingredients
icon='Ingredients.dmi'
var/bigicon = 'Carrot.png'
Carrot
icon_state="carrot"
bigicon = 'Carrot.png'
verb
Get()
set src in view(1)
var/fullname = usr.lastname + ", " + usr.firstname
if(!usr.lastname)
fullname = usr.firstname
var/obj/Ingredients/C = new()
C = src
// del(src)
src.Move(usr.bag)
usr.ingredients += C
view()<<"[fullname] picked up [C]."

mob
var
cooking_bowl = new/list()
ingredients = new/list()
choppingboard = new/list()
bag = new/list()


Problem description:

Upon using the Get() verb, I'm given this runtime error.

runtime error: undefined proc or verb /list/Enter().

proc name: Get (/obj/Ingredients/verb/Get)
source file: Cooking.dm,47
usr: RiceINF (/mob)
src: Carrot (/obj/Ingredients/Carrot)
usr.loc: the turf (54,38,2) (/turf)
src.loc: the turf (55,39,2) (/turf)
call stack:
Carrot (/obj/Ingredients/Carrot): Get()



Best response
This is the problem:
src.Move(usr.bag)

The Move() proc allows movable atoms to move between atoms.

Lists aren't atoms, so they're not involved in movement at all. You can add things to them like this:
usr.bag += src

// or this:
usr.bag.Add(src)

This is how it should be, I think:
obj
Ingredients
icon='Ingredients.dmi'
var/bigicon = 'Carrot.png'
Carrot
icon_state="carrot"
bigicon = 'Carrot.png'

verb
Get()
set src in view(1)
usr.bag += src
usr.ingredients += src
view() << "[usr.FullName()] picked up [src]."

mob
var
list
cooking_bowl = new
ingredients = new
choppingboard = new
bag = new

proc
FullName()
if(lastname)
return "[lastname], [firstname]"
else
return firstname


A few other points:
* The C variable is not necessary (you're instantiating it, and then setting it to src, ignoring what you just instantiated).
* I refactored your "full name" code into a mob proc. You're not going to want to copy/paste it everywhere you need it. You could optimize it by storing the full name as a variable and only updating it whenever firstname or lastname are modified, if they're not likely to change very often.
* List variables should have the list type. I modified your mob var declarations to have the list type.
Why is it that I can use Move() on contents and not a list which I have created?

Also, I was aware of the situation with C (I was testing and circumventing the error in a previous test before editing and uploading this code, my mistake).

What's the difference between 'var/list = new/list()' and 'var/list/variable = new'?

Thanks a lot for your help.
In response to RiceINF
Why is it that I can use Move() on contents and not a list which I have created?
You can't do a.Move(b.contents), you do a.Move(b) and a is added to b.contents through that.

What's the difference between 'var/list = new/list()' and 'var/list/variable = new'?
// This is a variable named "list" with no type.
// Its initial value is a new empty list.
var/list = new/list()
// Since the variable doesn't have the list type,
// the variable can't be used to access list vars and procs.
list.Add(123) // doesn't work

// This is a variable named "variable" with type "list".
// Its initial value is a new empty list.
// "new" uses the type of the variable if no type is specified.
var/list/variable = new
variable.Add(123) // works

(This goes for all types, not just list)
Got it. Cheers.
In response to Kaiochao
One more question: how would I go about deleting the object from the map whilst it is put into the user's ingredients list?

del(src) deletes the object full stop.

I attempted creating a clone of it and adding that to the ingredients list, whilst deleting src although that didn't work.
In response to RiceINF
You can remove it from the map by moving it into the player with Move(usr) or by setting its loc variable to null.
In response to Kaiochao
To piggyback off of Kaiochao's answer, setting an obj's loc to null will move it off of the map entirely and allow the engine to garbage collect it. If you don't want it to be garbage collected, just keep a reference to it (which is what you would be doing by adding it to the incredients list).

When you move something to a player (Move(usr)) what you're really doing is adding it to the player's contents list. You can find more information about it in the DM reference.
Ah, I see. I just want to get rid of it from the map, so I guess setting the loc to null will be sufficient.