ID:270646
 
how do you make it so you create a new obj:
new /obj/thing

and then set it's location and also the direction it is facing?

example: I kill a NPC and it freezes and flicks a dieing scene, then a object known as 'copse' replaces it facing the same direction, then the NPC is deleted, leaving the corpse.
Why not just go:

var/obj/o = new whatever(location)
o.dir=somedir


Additionally, I believe there is a syntax for specifying particular values for variables that a new object can have, using braces, but I'm not sure how that works - I believe the Blue Book mentions it.
In response to Jp
what the hell is the blue book?
In response to Carved in Shadows
The Blue Book™ was originally created by Dan, one of the founders of BYOND. It was being sold at the BYOND Store for some money, so BYOND could be developed and maintained.

Now, however, it's free and anyone may read it. In fact, you're encouraged to read it, as you'll learn a lot more by the time you finished the book.

Don't say it's too long. I spend most of my time behind my computer, and within only four hours I managed to read 5 chapters or so. Then again, I already have some experience and was searching for ways to improve my inefficent methods, but I didn't skip ahead or anything. Well, apart from a few chapters. =P

Read it. Trust me, you'll become a MUCH better coder if you do. Read it and most importantly: understand it.
In response to Carved in Shadows
It was a massive guide (About 200 pages, I believe) to the DM language. It was produced back in the days of BYOND 2.0, though, so it's slightly out of date.

It isn't sold anymore, but there is a .pdf of it sitting around somewhere. Use the forum search.
Carved in Shadows wrote:
how do you make it so you create a new obj and then set it's location and also the direction it is facing?

As stated in the Blue Book™, there are two ways to accomplish your task:

1) You can create the object with variable reference, and then edit it on the spot.

var/obj/O=new //create a new object
O.name="Pie" //set it's name to "Pie"


2) You can use New() and perform additional things upon creation. In the case of your fallen NPC, I would do something like this:

//we assume the NPC died and we're in the death() proc or such
new/obj/corpse(src.loc,icon(src.icon,"corpse"),src.dir)


obj/corpse //our GLOBAL corpse. This is for ALL mobs, regardless of which NPC wants it
New(loc,icon/I,direction)
icon=I //set the icon to the NPCs' specified icon
dir=direction //set the direction to the NPCs' specified direction


The above code assumes that all of your NPCs have their own icon files. For instance, a slime would have a file called "slime.dmi" or something similar. This file would have a blank icon_state for the NPC when it's alive, and a special "corpse" icon_state for when the NPC has died. You then don't have to worry about your NPCs dying and assigning hundreds of corpses for every possible NPC, but instead only need to focus on creating a "corpse" icon_state in their respective icons. The death procedure should then become a global procedure for all NPCs, and possibly even players.

Challenge: could you adjust the code above so that it'll move the inventory of the player to the corpse, and allow players passing by to 'loot' the corpse?
In response to Jp
Jp wrote:
It isn't sold anymore, but there is a .pdf of it sitting around somewhere. Use the forum search.

You mean this PDF?
In response to Jp
You just use them directly after a type path to specify different default values.
obj/sword
var/attack_power = 5

mob/shopkeep/verb/buy()
set src in view()
usr.contents += new /obj/sword

mob/master_blacksmith/buy()
set src in view()
usr.contents += new /obj/sword{attack_power = 10}

I don't think you can use variables to specify the default value though. I recall trying that once and having the compiler yell at me. So, if I recall correctly, you have to set it to a constant.