ID:683395
 
(See the best response by GhostAnime.)
Error code:
Namone logged in!
You exited the small cotage.
runtime error: type mismatch: the grass (13,11,1) (/turf/grass) += 5
proc name: DblClick (/obj/gold/DblClick)
usr: Namone (/mob)
src: the gold (/obj/gold)
call stack:
the gold (/obj/gold): DblClick(the grass (13,11,1) (/turf/grass), "mapwindow.map", "icon-x=17;icon-y=17;left=1;scr...")
You recieved 5 gold!

(Btw, this is a runtime error, it compiles fine.)

//Main.dm//

/*
Delcares mobs, and there variables. Along with Login() parameters.
Also declares world and turfs, along with some objects related to
the mob/player.
*/


//Mobs
mob
var
purse = 0
amount

Login()
icon = 'Icons.dmi'
world << "[usr.key] logged in!"
switch(alert("Gender Select", "What Gender?", "Male", "Female"))
if("Male")
icon_state = "Male"
loc = locate(1,1,1)
if("Female")
icon_state = "Female"
loc = locate(1,1,1)
//Turfs
turf
icon = 'Icons.dmi'
grass
icon_state = "Grass"
house
icon_state = "House"
wall
icon_state = "Wall"
density = 1
opacity = 1

//Objects relating to mob/player
obj
icon = 'Icons.dmi'
gold
icon_state = "Gold"
DblClick(mob/purse)
usr << "You recieved 5 gold!"
purse += 5
Move(usr)


//Stat panels and such
mob
Stat()
stat("Gold:", purse)
if(src == usr) statpanel("Inventory", src.contents)


//Areas
area
House
Entered()
usr << "You entered a small cotage."
Exited()
usr << "You exited the small cotage."


Basically I want to be able to pick up the gold, and move it to my inventory, but it doesn't seem to work.

Thanks,
Namone


Best response
My, my. I must say that snippet gave me quite a scare with the riddles of abuses present inside. I'll go through each one that I saw:

1)
    Login()
icon = 'Icons.dmi'
world << "[usr.key] logged in!"
switch(alert("Gender Select", "What Gender?", "Male", "Female"))
if("Male")
icon_state = "Male"
loc = locate(1,1,1)
if("Female")
icon_state = "Female"
loc = locate(1,1,1)


In Login(), the usr is usually set to the src (the source, aka the object that has the procedure that was called). usr is ultimately the one who called that procedure. If a /mob did not call a procedure directly (as is the case with movement procedures!)

If you want to err on the safe side, use src.name instead of usr.name. Omitting usr., thus having just "name", will make DM assume you are asking for src.name (so icon_state == src.icon_state).

Now, the one thing I want to point out is the redundancy (repeat) of the location. After your switch statement, in both choices, you locate the /mob to the same location. As a programmer, you will want to look for shortcuts - and what you could have done is do the loc change OUTSIDE the switch() statement, which affects the /mob no matter the choice.

Actually, if you do that, you don't need the switch(), you can set the value directly:
icon_state = alert("Gender Select", "What Gender?", "Male", "Female")



2) Your actual problem
obj
icon = 'Icons.dmi'
gold
icon_state = "Gold"
DblClick(mob/purse)
usr << "You recieved 5 gold!"
purse += 5
Move(usr)


You should take a look at the argument DM reference entry. This is not how arguments work. (To clarify: arguments are the items in the parenthesis/"round brackets", which is purse here).

If you look at the DblClick() entry, the first argument is "location" - the item that was clicked!

So you are setting a variable named "purse" to the object to add money to another variable named "purse"... uh oh! Remember, computers are not smart - we tell them exactly what to do.

The solution to this is get rid of the argument! DblClick() is one of those procedures where usr is directly defined.

Remember what I said about omitting the object when accessing the variable, that it assumes it is src.? Well, make sure you tell DM to add 5 to usr.purse.

(PS: this is the reason for your runtime error. Since the argument was location, and if you read the error obtained, it was trying to do location += value instead, as you wanted, usr variable += value)


3)
//Areas
area
House
Entered()
usr << "You entered a small cotage."
Exited()
usr << "You exited the small cotage."


See the end of point #1. Movement procedures, including Entered() and Exited(), are one set of procedures where you DO NOT WANT TO USE USR!

Instead, use the argument. If you look up the entries in DM reference, the first argument is the object that entered/exited... use that!

Remember though, just telling the argument is a /mob doesn't help - movement procs (and most others) do not check the type that is passed on to the variable... meaning thatthe object that called Entered() may actually be a moving /obj, not the /mob you were expecting (so safety check with ismob()!)

-------------
Edit: Thanks DC for catching the mistake for the DblClick() link
Your arguments for DblClick() are wrong:
atom/DblClick(location,control,params)


The first argument is the location of the object that was clicked, not the mob that clicked it. You need to use usr here, as you did with Move(), and you'll want to add to usr.purse.

Also, unless you want the gold bag to sit in your inventory as well as increase your purse value, you should probably just do del(src) to remove the gold bag.

<edit>
Aww, ninja'd by a much better explanation!

Just one note: it's atom/DblClick() and not client/DblClick().