ID:151139
 
I have to be close with this, take a look:
obj/Money
Gold

var
//mob stat modifiers
HP
dexterity
shield
armor
iq
immunity
Addkarma
money
Gold

duration //number of additional digestion rounds
delay //pause (in ticks) between digestion rounds
//if duration==0, delay gives initial pause

parasite //parasite type (if any)
rot //shelf-HP (in ticks)


proc
StoreDesc()
DigestDesc()
Tick()

verb/Store()

obj/Money
Gold
gender="male"
icon = 'Money.dmi'
money=10


obj/npc

shopkeeper
icon = 'Jim.dmi'
density = 1
name = "Weapons & Armor Vendor"
//mood = 0
//step_mode = -1
verb/Buy()//b in selling
set src in view(2)// Makes sure that the shopkeeper is in view of the player
var/selling = input("What do you wish to buy?") in list("Sword","Shield","Tazer") // list of what the shopkeeper sells
var/cost
if(selling == "Sword")
cost = 20
if(selling == "Shield")
cost = 5
if(selling == "Tazer")
cost = 15
var/choice = input("That will be [cost] Gold. You have [usr.Gold] Gold") in list("Yes","No")
if(choice == "Yes") // If the user says yes and he can afford the weapon, give it to him.
// Define the costs of each weapon
if(usr.Gold >= cost)
usr.Gold -= cost
if(selling=="Sword") new/obj/Weapon/Sword(usr)
if(selling=="Shield") new/obj/Armor/Shield(usr)
if(selling=="Tazer") new/obj/Weapon/Tazer(usr)
else
usr<<"You don't have enough Gold!"



BUT! The only problem i have is this:
Shopkeeper.dm:19:error:usr.Gold:bad var
Shopkeeper.dm:22:error:usr.Gold:bad var
Shopkeeper.dm:23:error:usr.Gold:bad var


I've but var/Gold but it doesn't seem to help, and suggestions? Thanks,
Gilser
Looks to me like your shopkeeper code is using gold as if it were a variable from your mob when you have gold as an object.
On 3/8/01 10:03 pm Gilser wrote:

BUT! The only problem i have is this:
Shopkeeper.dm:19:error:usr.Gold:bad var
Shopkeeper.dm:22:error:usr.Gold:bad var
Shopkeeper.dm:23:error:usr.Gold:bad var


I've but var/Gold but it doesn't seem to help, and suggestions? Thanks,

Hi Gilser,

This is the problem that Deadron and I were debating earlier, in the General forum. Anytime you get something like:

usr.Gold: bad var

it means that the usr's type doesn't have the Gold var defined for it. What type is usr? It is a /mob. This is because, in general, the usr can be any mob calling the verb. For instance, if you might have two types of players: /mob/elf and /mob/dwarf. Either of these could go to the shopkeeper, so the usr must be defined as the most general type, /mob.

So this probably means that you don't have var/Gold defined underneath /mob (I'm guessing it's defined underneath /mob/player or something, right?) You have a couple of different options here:

First, you could just define all of your pc variables under /mob. Then usr.Gold will exist because 'mob' will have a Gold var defined.

Or you could tell the compiler that usr is in fact a mob/player (or whatever). As Guy T. suggested you can do this will a snippet like this:

mob/player/var/M = usr
if(!istype(M)) // checks if usr is in fact a mob/player
return // nope, it's not .. get out of here

... // do the rest of your code, but use M for usr

Finally, you could use DMs built-in functionality that says "screw the compiler, usr is a mob/player". To do this, use the colon rather than dot operator, eg:

usr:Gold = ...

But I would really advise against this last method until you are sure you understand exactly what's going on. It is much safer to have the compiler do the checking for you. If you are at all confused, please don't hesitate to ask. The gurus here can probably explain it much better than myself.

[Edit] I just read Karver's response to this and he noticed something that I failed to see, that you don't appear to even be defining Gold as any sort of mob var at all. You might want to clarify your approach here.

In response to Tom H.
Ok, I just put that in and to my surprise it worked! All I needed was
mob/
var/Gold

But...if you could look at my code for another problem, the gold won't store! When you store gold, its supposed to add like money, but instead, storing gold does nothing and food adds money! Wuh oh!
Thankk
Gilser