ID:273326
 
Say I have instances of waves or enemies in my game. Where enemies spawn in a location. Can I have multiply enemies spawn by doing something like:

new/mob/NPC/enemy/(locate(40 to 37,12 to 8,1))

Right now I'm using a for() loop to change the location, but I'm sure there's better way.
Are you creating an enemy everytime ? (in the loop)

I am quite interested with your
new/mob/NPC/enemy/(locate(40 to 37,12 to 8,1)) // never seen such syntax b4


Though if you use new in your loop it would be real real laggy.It uses more of CPU.

I don't know about your special locate thingy but reducing new usage can really help you.
There is no better way, and the alternative you provided will boil down to a loop as well, internally.

Best you could is to just keep your loop as efficient as possible.
In response to Getenks (#1)
That's a major problem at the moment is lag, during the creation and even after. If more than around 15 enemies are on screen at once I have major lag issues. So, I'm looking for a better solution.

But that syntax, isn't that how you are suppose to do it excluding the "to"s? =\
In response to Metamorphman (#2)
I'll try adding a sleep timer to see if it cuts down on lag. Thanks.
In response to Ulterior Motives (#4)
Geek Programmers don't really use all procedures frequently, they have their eyes on the 'CPU'. They try to use the CPU as less as possible.

As far as I know - I can list down several procedures in the decreasing order of their CPU usage (this is empirical data):
  1. New
  2. Del
  3. All_Hub related // this can also be placed at the top if your internet speed sucks
  4. All win related procedures (eg.winset,get..)
  5. loops // I suppose


Thats all I know and they are only from my experience so I can't say that data can be trusted.

Why don't you try not deling enemies.Just spawn them to the grave and then respawn to a random location.(this can reduce the lag and can work perfect for you)

But that syntax, isn't that how you are suppose to do it excluding the "to"s? =\
Oh yeah , I was freaked out only because of the "to"s.

mob/Enemy
proc/Death()
src.loc=locate("Grave")
New(loc)
src.HP=src.MaxHP
src.MP=src.MaxMP
src.loc=locate(loc)


You can execute the New() whenever you want. It does not create an anything but its called when something is created.

For instance
new/mob/Enemy // this would call Enemy.New()

In response to Getenks (#5)
Getenks wrote:
src.loc=locate(loc)

That is the mostly stupidly-roundtabout thing I have ever seen.

new/mob/Enemy // this would call Enemy.New()

No.
Option 1 is to use block(), which will give you a list of turfs. Then, you can loop through that list and create a mob on each turf.

Option 2 is to place an area on the map, and just create the mobs in the area itself. They'll automatically be moved to the first (which means lowest z, then lowest y, then lowest x) available turf.

Option 2 is going to be slightly slower, because each mob being placed is independent of the others, so mob N has to loop through (N-1) occupied turfs before it finds an open one. However, I doubt it will make much of a difference, and if the areas you want to spawn mobs into are static and non-overlapping, I suggest using that, because it's easier to manage.
In response to Garthor (#7)
I used the second way and it's way better, that what I was doing.
In response to Popisfizzy (#6)
Popisfizzy wrote:
Getenks wrote:
src.loc=locate(loc)

That is the mostly stupidly-roundtabout thing I have ever seen.

new/mob/Enemy // this would call Enemy.New()

No.

I was not precise in my writing. so duh..

refer http://www.byond.com/docs/ref/

cause as far as I know newing an object does call New().
In response to Getenks (#9)
It doesn't. The object doesn't exist, and therefore a proc can't be called. First it's created, and then it's constructor (New() in DM) is run, but that doesn't directly call it. Saying it does is misleading.
In response to Popisfizzy (#10)
Well, when I create a datum in DM it does excecute New().Thats why I said it calls New().( I am sure about this ).

Btw, what I said(meant) is that it - calls New() after the datum is created - thats what I experienced till 454.

Edit: What you are telling is deep in DM.I am not much into the depth in DM knowing constructor or whatever but by experience if you ask any BYOND Game Dev he would say newing will result into the newdatum.New(). (not knowing whether constructor would call or new would call ) - but the point is that it calls and executes everything line of code in the newdatum.New().
In response to Getenks (#11)
But it's misleading to say that. new /path doesn't call /path.New() because there's no /path object yet created. First, the VM creates the object and then calls its New() proc, which is much different than calling /path.New() directly. I imagine it's similar with /path.Del().