ID:155814
 
In a little project I'm creating, what I am attempting to do is have multiple instances of the same 32 by 32 object placed in different areas on my map. What I am wanting to know is, what is the best way to go about doing this?

Should I just make a big list of the max # of instanced objects needed using newlist()? Or should I utilize a while() loop and just constantly create a new instance of an object until I don't need it anymore?

Please assist me with this, and thanks!


Edit: Am I going about this wrong? Maybe I have some improper memories...do you only need to create 1 instance of an object, and then you can place it in as many places as you want on your map, as long as it's the same object?
Each time you create a new() object it creates a brand new instance of that object. There's no way to place the same object at multiple locations because objects only have one 'loc' variable.
In response to Nadrew (#1)
Then what would be the most efficient method?
In response to OrangeWeapons (#2)
All depends on how you need the objects, if you need it to be a simple constant list of things in specific places then just place them on the map manually using the map editor. Using newlist() is basically going to be the same thing.

Now if you need the stuff to be easily modified and dynamic you'll want to write some kind of loader for them, which can involve a simple while() to create objects and be done with it, or a more detailed event loop that keeps track and handles the objects as needed.

The most efficient way is the way that suites your needs the best, worrying about how many resources it takes should come after you figure out what you need; but by then you'll have things working how you need them to work and just have to refine what you have to run smoother (if needed).
In response to Nadrew (#3)
Ah, alright, thank-you. I feel that the best method would be a while loop...but I'm not positive. Can I go about something such as this?

var/can_create = 1
while(can_create)
var/obj/box/B = new
B.loc = locate(1,1,1)
B.loc = locate(2,2,1)
can_create = !can_create


Or would that be stupid and inefficient? (It's just an example, I plan to be creating around 30 objects at once that are all the same exact object)

I'm trying to think of another way in which it could be done...

<small>>Now if you need the stuff to be easily modified and dynamic you'll want to write some kind of loader for them, which can involve a simple while() to create objects and be done with it, or a more detailed event loop that keeps track and handles the objects as needed.</small>

That is what I want to do. Sorry for asking so many questions, thanks for the help too.
In response to OrangeWeapons (#4)
The problem with the code you showed is that you're changing the first object you create multiple times, which will just move it around and not actually create a new each time. You'd be creating more than one, but they'd all end up in the same place.

Something like
var
creating = 0
create_x = 1
create_y = 1
create_z = 1
while(creating < 100)
new/obj/my_obj(locate(create_x,create_y,create_z))
create_x++
create_y++ // Just as an example, you can figure out how to handle changing these or find another method.
creating++
sleep(1)


Just an example, I'm sure you can figure out what to do from here.
In response to Nadrew (#5)
Ah, I see. Sometimes even the smallest things in programming can make your brain-gears grind when you haven't really worked with them. Thanks Nadrew!
In response to Nadrew (#5)
I guess I can't. Here's what I have done:

            if(4)//bishop
var/diag=0
var/mob/bishop/bs=new
while(diag<9)
diag++
var/obj/path/pp=new
var/obj/path/pp2=new
var/obj/path/pp3=new
var/obj/path/pp4=new
pp.loc=locate(bs.x+diag,bs.y+diag,bs.z)
pp2.loc=locate(bs.x-diag,bs.y+diag,bs.z)
pp3.loc=locate(bs.x-diag,bs.y-diag,bs.z)
pp4.loc=locate(bs.x+diag,bs.y-diag,bs.z)
sleep(1)

I know, it's not the most efficient way most likely, but I'm really just trying to get this done. Also, idk why if(4) didn't position itself properly
In response to OrangeWeapons (#7)
For what it's worth, you should probably implement your chess pieces (they are chess pieces right?) by writing a procedure that gives you a list of valid board positions in a line (horizontal, vertical, diagonal), and then using that one procedure for the bishop, rook, and queen. I wrote a chess variant game for last year's GIAD, so you might find that useful - here's the source. Keep in mind that that's absolutely not the best code - in particular, it was written under some pretty significant time pressure. But it might give you some ideas.

Hope that helps.