ID:154811
 
I read about these and want to make sure I full understand. Correct me if I'm wrong please and would appreciate examples.

But as far as I know New() adds a new variable, procedure or property. And new() adds a new object (only objects?). I still don't fully understand the potentials, I would appreciate extending my understanding here.
New() is the actual procedure being run when you use new()
In response to Lugia319
Lugia319 wrote:
New() is the actual procedure being run when you use new()

May I have an example?
In response to TheDarkChakra
obj
New()
..()
world << "[src] was created!"


This will output "[obj] was created" whenever you do something like

var/obj/O = new(src.loc)
In response to TheDarkChakra
obj
Death_Blossom
New()
for(mob/player/p in world)
p.dead = 1

mob
player
verb
Create_Death_Blossom()
var/obj/Death_Blossom/this = new()
this.loc = usr.loc

Basically, when you activate anything that creates an object, it runs that object's New() procedure. This is probably a horrible example with bugs, but it shows you what I mean. When the player activates the "Create_Death_Blossom" verb, it uses new() to make the object, and as it's created, the object's New() proc is run, killing everyone on the server.
In response to Solomn Architect
This won't compile, you forgot to typecast the "this" variable, meaning the compiler will error when you try to use "this.loc". You should be doing:

var/obj/Death_Blossom/this = new()
this.loc = usr.loc

In response to Nadrew
As I said, it was a horrible example, however the place you pointed out was irrelevant to the subject at hand. My code wasn't meant to compile, it was meant to show what happens when new() triggers New(), whether or not the variable itself made sense. But alas, I cannot be too upset about being corrected, this is a forum for programmers of course.
In response to Lugia319
I suppose it struck me as odd that we don't create new objects by doing: New(/obj/type/)

As would be done with most procedures, but perhaps its because it's a built in proc that it is different?
In response to Solomn Architect
The point of an example is for him to test things out and see how the New() and new() work.
In response to Lugia319
It has been amended for correction.
In response to Solomn Architect
To demonstrate passing arguments to New:
obj/Death_Blossom
New(mob/creator)
// By default, this was created /inside/ the mob.
// Fix that by resetting the location to the mob's location.
loc = creator.loc

for(var/mob/player/p in world)
// don't kill the creator!
if(p == creator) continue

p << "[creator] spawned a death blossom!"
p.die()

mob/player
verb/Create_Death_Blossom()
// Create a new Death Blossom
// and pass src as the first argument,
// which tells New() who created it (above).
new /obj/Death_Blossom (src)
Let me clarify things.

First of all, New() is a datum proc. You won't be able to call it without the instance of datum itself.

Second, the syntax is:

new /datum_type(arg1,arg2,...)


The above code will create an instance of /datum_type. Then, it will call New(arg1,arg2,...).

It is not New() that creates the datum. new does that.

datum/proc/New does not do anything by default.

Other notes:
new(/datum_type)
// will not compile

var/some_datum/var_name = new(/datum_type)
// will create an instance of /some_datum
// and call its New proc with /datum_type as an argument, i.e. New(/datum_type)