ID:1792708
 
(See the best response by Ter13.)
Code:
obj/Creatables
var/neededtech=1
var/cost=1
New()
suffix="[FullNum(round(cost/usr.techmod),100)]z"
if(cost==1) del(src)
..()


Problem description:
Basically, I have no idea what the hell is the problem but, I've been trying to solve this problem for awhile, and I have been doing alot of work towards it but, it seems to not be solving the problem. I'm wondering if anyone else could help me solve it.

Additional Information
 source file: Scientists.dm,18
usr: null
src: Punching Bag (/obj/Creatables/Punching_Bag)
call stack:
Punching Bag (/obj/Creatables/Punching_Bag):
Best response
You can't use usr in New() like that.

I assume you are trying to create the object and give it properties based on the creator's stats?

What you want to do, is pass the mob that created the object into the initialization call of the creatable object via an argument:

obj/Creatables
var
neededtech = 1
cost = 1
New(atom/loc,mob/creator)
suffix = "[FullNum(round(cost/creator.techmod),100)]z"
if(cost==1)
src.loc = null //never call explicit deletion
..()


This would be how you'd use it:

var/obj/Creatables/Punching_Bag/b = new(loc,mob)


loc should be the turf or atom container where you want to create it. The first argument of new for ALL atoms should always be the location where the atom will be created. Before New() is actually called, the object will already be created and placed at loc.

mob should be the reference to the mob that created the object. If you are calling this from a verb or a mouse proc, you would use usr.
Thanks so much, I just want to learn alot of BYOND Coding, so I can make my game become better and better, thanks alot.