ID:1513651
 
(See the best response by Kaiochao.)
Code:
    Water
icon = 'Turfs.dmi'
icon_state = "Water"
density=1
verb
Fish()
set src in view(2)
var/r = rand(1,25)
var/a =new /obj/Items/Tools/Fishing_Pole
if(a in usr.contents)
if(r == 1)
usr<<"You caught nothing!"
else if(r == 2)
usr<<"You caught a Fish!"
usr.Fish+=1
else if(r == 3)
usr<<"You caught a Fish!"
usr.Fish+=1
else if(r == 4)
usr<<"You caught nothing!"
else if(r == 5)
usr<<"You caught nothing!"
else if(r == 6)
usr<<"You caught a Fish!"
usr.Fish+=1
else if(r== 7)
usr<<"Your rod broke!"
del a
else if(r>=8)
usr<<"You caught nothing!"


Problem description:
For some odd reason I cannot seem to get a grasp on object paths in DM. How can I delete the object out of the usr contents list and how can I check if it is in the list?
Best response
If you want to check if an object of a certain type is in the player's inventory, you can use locate().
// In general,
var some_object = locate(some_type) in some_list
// if some_list is some object, it'll search in the object's contents

var a = locate(/obj/Items/Tools/Fishing_Pole) in usr

// or even better,
var obj/Items/Tools/Fishing_Pole/a = locate() in usr
// with this, you have a variable defined as a fishing pole
// and you don't have to rewrite the type inside locate()

Now you have a reference to the object in usr (or null, if locate() doesn't find anything).
Also, you can improve your random chance code using switch():
switch(rand(1, 25))
if(1)
// rod breaks
if(2 to 4)
// caught a fish
else
// caught nothing
I was forgetting the locate function but also could you tell me how var obj/Whatever/Tool/Can/a how does that make the whole path a var shouldn't it corrupt the path? I know it works i'm just trying to make sense of it.
When you define a variable, the preceding type path is just a description of what that variable is. It also gives the compiler a heads-up on what variables that reference SHOULD have. For instance... if you define var/mob/A, you define the variable "A" as type of /mob. The compiler then knows that "A" should also have the same variables as any other mob, such as A.client, A.icon, A.density, etc etc

Try to compile these two.

proc/test()
var/a = new /mob()
world << a.icon

proc/test2()
var/mob/a = new()
world << a.icon


The first one should produce a compiling error because the compiler will not assume that a is a mob, because you did not typeset the variable to BE a mob (even though you assigned it to be one in the very same line).
In response to The WardenX
It's in the DM Reference under "var". When you make a new variable, you have the option of specifying a type for the variable.
var [type] [name] = [value]

// e.g.
// [type] = /obj/Items/Tools/Fishing_Pole
// [name] = a
// [value] = locate([type]) in usr
// becomes
var/obj/Items/Tools/Fishing_Pole/a = locate() in usr
Thanks for clearing that up for me Koshigia and Kaiochao!
In response to The WardenX
Glad to help =)