ID:139542
 
Code:
mob
shopkeeper
var/list/inventory = list()
name = "Shop Keeper"
Action()
set src in view(2)
//chat
switch(input(usr, "What would you like to do?") in list("Buy", "Sell"))
if("Buy")
var/obj/O = input(usr, "What would you like to buy?") in inventory
if(usr.money >= O.value)
usr.money -= O.value
usr.contents += new O
if("Sell")
if(!usr.contents)
//chat
else
var/obj/O = input(usr, "Which object would you like to sell?") in usr.contents
if(!O.value%2)
O.value += 1
switch(input(usr, "Are you sure you want to sell [O.name]?") in list("Yes", "No"))
if("Yes")
O.value /= 2
usr.contents -= O
usr.money += O.value
Viola
inventory = list(/obj/TV, /obj/rug)


Problem description:
When i run this, and try to buy something from the shopkeeper, i get an error message saying:
runtime error: Cannot read /obj/TV (/obj/TV).value
proc name: Action (/mob/shopkeeper/Action)
usr: Darkoro (/mob)
src: Shop Keeper (/mob/shopkeeper/Viola)
call stack:
Shop Keeper (/mob/shopkeeper/Viola): Action()

I guessed that i did something wrong (No duh sherlock?). So, how would I fix it?

For the record, Viola is the name of the shop keeper from the city of Viola. Hence the inventory var being declared in shopkeeper, and being overwritten (each city has different items in stock).
You can't check variables of a type path, it has to be an existing object.
Try using newlist(/obj/TV, /obj/rug) instead. The newlist() proc acts like list(), but if you fill the list with paths, it will create new instances of them automatically as if you typed list(new/obj/TV, new/obj/rug).
In response to Kaiochao
runtime error: Cannot create objects of type /obj/card.
proc name: Action (/mob/shopkeeper/Action)
usr: Darkoro (/mob)
src: Shop Keeper (/mob/shopkeeper/Viola)
call stack:
Shop Keeper (/mob/shopkeeper/Viola): Action()

i created a new obj just for this, because when i tried it with TV and rug it failed, and i assumed it was down to the fact that TV and rug where placed on the map (i dunno what gave me that idea, but hey.).

Anyway, thats the new Error message i get.
In response to Darkoro
Now that issue is the opposite: new() is expecting a type path, but you are giving it an actual object (and then it gives you a confusing error message).

You need to do new O.type(usr) instead of just new O(usr).
In response to Garthor
Thank you garthor, the code works fine now.