ID:264285
 
Code:
#define isWhole(number) (number==round(number,1))
obj/Weaponry
Knife
icon = 'Knife.dmi'
Price = 500
var/Material
Bump(atom/A)
var/mob/O = Owner
if(ismob(A))
var/mob/M = A
var/dmg = round(O.NeedleSkill + O.Taijutsu)
switch(Material)
if("Bronze") dmg*=1
if("Iron") dmg*=1.5
if("Steel") dmg*=2
M.Health -= dmg
view(M)<<"[M] was hit by \a [src] for [dmg]"
O.NeedleEXP += M.Level
O.NeedleLvlUp()
M.Death(O)
if(istype(A,/obj/Training/Training_Log))
var/rndm = rand(20,30)
O.NeedleEXP += rndm
O.NeedleLvlUp()
O<<output("<font size=1>You gained [rndm] Needle experience","Crap")
del(src)
New()
src.name = "[src.Material] Knife"
src.suffix = "([Amount])"
..()
Bronze
Material = "Bronze"
Amount = 5
Iron
Material = "Iron"
Amount = 5
Steel
Material = "Steel"
Amount = 5
verb
Drop()
for(var/obj/Weaponry/Needle/K in usr.contents)
if(!src.Amount)
del(src)
var/drop = input("How many do you want to drop?\n- You have [src.Amount] [src]\s","Drop") as num|null
if(drop > src.Amount || !isWhole(drop) || drop <= 0) return
src.Amount -= abs(drop)
src.suffix = "([src.Amount])"
var/obj/Weaponry/Needle/D = new(usr.loc)
D.Amount = drop
if(!src.Amount) del(src)
usr.AutoSave()


Problem description:
Okay I have the weapon in my inventory. When I right click it and select Drop, nothing happens but the AutoSave() proc. Any reason for this? It worked before, now it just stopped working.
Should this be /obj/Weaponry/Knife/K?

for(var/obj/Weaponry/Needle/K in usr.contents)
In response to Jp (#1)
Yeah sorry. Mistype. Still won't work.
//Yadda
verb
Drop()
for(var/obj/Weaponry/Knife/K in usr.contents)
if(!K.Amount) del(K)
else
var/drop = input("How many do you want to drop?\n- You have [src.Amount] [src]\s","Drop") as num|null
if(drop > src.Amount || !isWhole(drop) || drop <= 0) return
src.Amount -= abs(drop)
src.suffix = "([src.Amount])"
var/obj/Weaponry/Knife/D = new(usr.loc)
D.Amount = drop
if(!K.Amount) del(K)
usr.AutoSave()
In response to Mizukouken Ketsu (#2)
Mizukouken Ketsu wrote:

Did you consider applying debug messages?
It's a great case for them to prove useful!

                for(var/obj/Weaponry/Knife/K in usr.contents)
if(!K.Amount) del(K)
else
//(...)
usr.AutoSave()


You're either not entering the for loop, or you don't get to the else statement, so set up a little message within the for loop and one inside the if clause and you'll be one step further ;)
Why are you still using that for() loop? Your whole input() part is looping, and is also depending on the if() statement. That's improper. Remove the loop and just use src
In response to Kaioken (#4)
Not 100% sure what you meant by only using src, but I think that's it (or at least close to it). I tested it, and same problem persists :\
//Yadda
verb
Drop()
if(!src.Amount) del(src)
else if(src.Amount)
var/drop = input("How many do you want to drop?\n- You have [src.Amount] [src]\s","Drop") as num|null
if(drop > src.Amount || !isWhole(drop) || drop <= 0) return
src.Amount -= abs(drop)
src.suffix = "([src.Amount])"
var/obj/Weaponry/Knife/D = new(usr.loc)
D.Amount = drop
if(!src.Amount) del(src)
usr.AutoSave()
In response to Mizukouken Ketsu (#5)
Apparently it's supposed to work, but you don't need the 'else if' anyway. Not only you shouldn't need to check the same condition twice, but del src effectively stops the proc similarly to returning, so an else check afterwards is superfluous.
Also, mind you've allowed the player to choose 'cancel' with the input(), which will return null, likely passing your current checking methods.
In response to Kaioken (#6)
It's still skipping everything except the AutoSave() proc.

//Yadda
verb
Drop()
if(!src.Amount) del(src)
var/drop = input("How many do you want to drop?\n- You have [src.Amount] [src]\s","Drop") as num
if(drop > src.Amount || !isWhole(drop) || drop <= 0) return
src.Amount -= abs(drop)
src.suffix = "([src.Amount])"
var/obj/Weaponry/Knife/D = new(usr.loc)
D.Amount = drop
if(!src.Amount) del(src)
usr.AutoSave()
In response to Mizukouken Ketsu (#7)
So you're not even getting the input() window? That's, honestly, quite strange. I assume amount isn't 0, null, or ""?
In response to Mizukouken Ketsu (#7)
Hm, it is weird. Meh, try removing the if() check to see if the condition is really [not] satisfied. Maybe AutoSave() is really just called... automatically.

If it still doesn't work after that, while it normally shouldn't make a difference, try sticking input()'s first argument explicitly, to target the player usr.
In response to Jp (#8)
Nope. The amount is not false/null.
In response to Kaioken (#9)
Still won't happen :\

        verb
Drop()
//if(!src.Amount) del(src)
var/drop = input(usr,"How many do you want to drop?\n- You have [src.Amount] [src]\s","Drop") as num
//if(drop > src.Amount || !isWhole(drop) || drop <= 0) return
src.Amount -= abs(drop)
src.suffix = "([src.Amount])"
var/obj/Weaponry/Knife/D = new(usr.loc)
D.Amount = drop
//if(!src.Amount) del(src)
usr.AutoSave()
In response to Mizukouken Ketsu (#11)
What about if you do-
verb
Drop()
world << "[src],[usr]"

Make sure the verb is really executing.. perhaps some other Drop() is?
In response to Kaioken (#12)
How's that possible when I'm right clicking the object in my contents xD
In response to Kaioken (#12)
Nevermind I fixed it. An error elsewhere caused it to not execute the verb correctly.
In response to Mizukouken Ketsu (#13)
mob/New()
contents+=new/obj/blargh()

obj/blargh/verb/Test()
set src in usr
usr << "This is a blargh tet"

obj/verb/Test()
set src in usr
usr << "This is a test"


Try it.
In response to Mizukouken Ketsu (#13)
If you want to get into the semantics of whether it is technically possible, then it is. =P What I'm not sure about is how come that input() isn't executed when you click the verb. Even if I copy and paste it to a test project, it works for me (as far as the input() is concerned at least), as expected. Does a debug message appear?
Might be worth posting the full node path of the verb (for example, /obj/myitem/verb/MyVerb), and checking if you have another Drop() anywhere. Might.

EDIT: Ah, you fixed it. >_>
Not enlightening us on what it was, though? :P
In response to Kaioken (#16)
Problem solved. An error elsewhere prevented the verb from being executed properly.
In response to Jp (#15)
(This won't compile because of a duplicate definition error, but your example is good if you change obj/verb/Test() to mob/verb/Test())
In response to Kaioken (#18)
Not quite. I'm going for lack-of-default-proc-screwing-up-inheritance here.

But yes, that'll probably give you a duplicate definition error. This won't:

mob/New()
contents+=new/obj/blargh()

obj/blargh/Test()
set src in usr
usr << "This is a blargh tet"

obj/verb/Test()
set src in usr
usr << "This is a test"