ID:150021
 
Alright, I had previously thought of myself as a good BYOND programmer, at least with my experience, now I am not so sure. This is the buy code with which I am having so many problems.
buy(mob/npc/people/interact/shopkeeper/M in oview(1))
set desc = "Buy stuff from a mob near you!"
set category = "Item"
usr << "Command temporarily disabled."
if(istype(M))
var/obj/itemchosen = input("What would you like?","Buy","") in M:shop
usr << "[itemchosen]?"
if(usr:gold <= itemchosen:price - 1)
usr << "You don't have enough gold!"
else
usr:gold -= itemchosen:price
itemchosen:Move(usr)

Hopefully that formatted decently, anyhow, I keep getting a runtime error, which looks like this...
runtime error: Cannot read null.price.
proc name: buy (/mob/pc/verb/buy)
source file: mob.pc.verb.dm,125
usr: Polatrite (/mob/pc/imp/acolyte)
src: Polatrite (/mob/pc/imp/acolyte)
call stack:
Polatrite (/mob/pc/imp/acolyte): buy(Bob Dole (/mob/npc/people/interact/shopkeeper/Bob_Dole))
/obj/equipment/weapon/Terila/club?

I can't begin to understand why it won't read the price, is this because the object doesn't exist and needs to be created, or what? It doesn't make sense, please help! :P

Polatrite, Assassin of the Sun

Postscript: If you need to know anything about my variables or what not, be sure to contact me and ask more questions.
It appears that the M:shop list isn't providing anything for input() to work with, so it's not giving you a choice of what to buy (or at least, you didn't mention it if it did) and it's returning "" as an answer because that's the default value you gave it.

For debugging purposes, before the line that uses input(), try this:
usr << "Debugging M:shop ([M:shop:len] item\s)"
for(var/item in M:shop) usr << "[item]"

I predict that one of two things will happen: Either this will tell you that M:shop contains 0 items, or M:shop is not a valid list and that first line will produce an error, probably saying that either it can't read null.len or len is a bad var.

If all else fails, I have a tidy piece of shopkeeper code in today's BYONDscape article that could probably help you.

Lummox JR
In response to Lummox JR
have you told it what to do if price = 0?That what your problem soulds like but i dont know
In response to Scoobert
Scoobert wrote:
have you told it what to do if price = 0?That what your problem soulds like but i dont know

Nope, if price was 0 then he wouldn't be having any trouble. The problem is that itemchosen is null, so to trace it back he has to find out what's going wrong in the input() proc.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Nope, if price was 0 then he wouldn't be having any trouble. The problem is that itemchosen is null, so to trace it back he has to find out what's going wrong in the input() proc.

Lummox JR

Same goes for real life too. If prices were 0, I wouldn't be having any troubles at all.
In response to Lummox JR
Well, I tried those two lines of code you gave me, and here is the new runtime output...

Debugging M:shop (2 items)
/obj/equipment/weapon/Terila/club
/obj/equipment/weapon/Terila/spiked_club
runtime error: Cannot read null.price.
proc name: buy (/mob/pc/verb/buy)
source file: mob.pc.verb.dm,127
usr: Polatrite (/mob/pc/imp/acolyte)
src: Polatrite (/mob/pc/imp/acolyte)
call stack:
Polatrite (/mob/pc/imp/acolyte): buy(Bob Dole (/mob/npc/people/interact/shopkeeper/Bob_Dole))
/obj/equipment/weapon/Terila/club?

I am also in the process of looking over your BYONDscape article.

Polatrite, Assassin of the Sun (wants to have a word with the deliquent that stole his game, Dragon Warrior Nova)
In response to Skysaw
well ok but there are some odd erors i get sometimes, and i mean the item has no price at all as in he never set the price
In response to Polatrite
Polatrite wrote:
Well, I tried those two lines of code you gave me, and here is the new runtime output...

Debugging M:shop (2 items)
/obj/equipment/weapon/Terila/club
/obj/equipment/weapon/Terila/spiked_club
runtime error: Cannot read null.price.

Bingo!
The problem you're having is that the itemchosen value returned by input() is a type, not an actual object. M:shop should be initialized with newlist() instead of list() to avoid this problem.

Another way around that problem is to do this:
var/obj/item=new itemchosen(src)
if(usr:gold<item.price)
...
del(item) // we don't need the item anymore
else
...
usr:gold-=item.price
item.loc=usr // give the item to the buyer

Lummox JR