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).
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).