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.
ID:150021
Jan 3 2002, 6:31 am
|
|
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. 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... 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) Lummox JR |
For debugging purposes, before the line that uses input(), try this:
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