ID:140015
 
Code:
    Cook
icon = 'Npcs.dmi'
icon_state = "cook"
DblClick()
switch(input("What would you like to do?",,"Buy","Sell"))
if("Sell")
var/obj/O = input("What do you wish to sell?")as obj in src.contents
switch(alert(usr,"Do you wanna sell [O] for [O.sell] Gold?"," ","Yes","No"))
if("Yes")
usr.gld += O.sell
del O
if("No")
src <<output("Fine.","comwindow")
if("Buy")
switch(alert(usr,"What do you want to buy?"," ","Herb","Corn","Nothing"))
if("Herb")
if(usr.gld >= 10)
src <<output("You buy a Herb!","comwindow")
new/item/Herb(usr)
usr.gld -= 10
else
src <<output("You need 10 gold","comwindow")
if("Corn")
if(usr.gld >= 20)
src <<output("You buy a Corn","comwindow")
new/item/Corn(usr)
usr.gld -= 20
else
src <<output("You need 20 gold","comwindow")
if("Nothing")
..()


Problem description: I get an error when trying to use the npc.

What error?
In response to JoEn00b
When I doubleclick the npc I get this:
runtime error: Cannot read null.sell
proc name: DblClick (/mob/NPC/Cook/DblClick)
usr: Mokona (/mob)
src: Cook (/mob/NPC/Cook)
call stack:
Cook (/mob/NPC/Cook): DblClick(Floor (10,6,3) (/turf/Floors/Floor), "Main.map1", "icon-x=7;icon-y=13;left=1;scre...")
In response to Mariahh
Ahh ok. That means for the Object, you need to define a variable called sell.

obj/items
var/sell = 0

Herb
sell = 10


Something to that effect.
In response to JoEn00b
JoEn00b wrote:
Ahh ok. That means for the Object, you need to define a variable called sell.

obj/items
> var/sell = 0
>
> Herb
> sell = 10

Something to that effect.
I already put a sell var in another file, and it still doesn't wrok
You're completely abusing "src" and "usr" in a proc.
The src in this case would be the /mob/NPC/Cook and the usr would be the Player.

So this line:
var/obj/O = input("What do you wish to sell?")as obj in src.contents
is trying to pick an /obj from the mob/NPC/Cook 's inventory and not the player's.

You're better off defining a new /mob ( ex; var/mob/Seller ) and assigning the "usr" to it so you can approach this with a clear thought.
Ex;
var/obj/O = input("What do you wish to sell?")as obj in Seller.contents



    Cook
icon = 'Npcs.dmi'
icon_state = "cook"
DblClick()
var/mob/Seller = usr
switch(input("What would you like to do?",,"Buy","Sell"))
if("Sell")
var/obj/O = input("What do you wish to sell?")as obj in Seller.contents
switch(alert(Seller,"Do you want to sell [O] for [O.sell] Gold?"," ","Yes","No"))
if("Yes")
Seller.gld += O.sell
del O
if("No")
Seller <<output("Fine.","comwindow")
if("Buy")
switch(alert(Seller,"What do you want to buy?"," ","Herb","Corn","Nothing"))
if("Herb")
if(Seller.gld >= 10)
Seller <<output("You buy a Herb!","comwindow")
new/item/Herb(Seller)
Seller.gld -= 10
else
Seller <<output("You need 10 gold!","comwindow")
if("Corn")
if(Seller.gld >= 20)
Seller <<output("You buy a Corn!","comwindow")
new/item/Corn(Seller)
Seller.gld -= 20
else
Seller <<output("You need 20 gold!","comwindow")
if("Nothing")
..() // Why do you have this?
In response to JoEn00b
A "null.whatever" error means that, a variable's value is null but you are attempting to access one of its members. For example, O is null but you are trying to access O.sell. If a variable were not defined, it would result in a compile-time error, or if the colon operator was used, a completely different runtime error.