ID:2074961
 
(See the best response by Kaiochao.)
Code:
turf
dirt
icon = 'Turfs.dmi'
icon_state = "dirt"
New()
..()
var occurence = rand(1,600)
switch(occurence)
if(1 to 300)
if(301 to 600)
new/obj/item/mineral/rock/small_rocks(src)


Problem description:

If I run new/obj/item/mineral/rock/small_rocks(src) from a verb it works... but this doesn't seem to work when I create a new turf...

anyone got any ideas why? I can change the icon state in the code and it works but it doesn't seem to want to make a new obj from there...
You aren't actually creating a new turf from what I understand.

Lummox JR said:
The turf isn't being deleted; its type is changing.

Quote from here.

Basically, New() for turfs is only called on world initialization.
That's strange.. because this works

    grass
icon = 'Turfs.dmi'
icon_state = "grass"
New()
src.icon_state = "grass[num2text(rand(1,4))]"


So... New on turfs only works for self assigned vars then?

Hrm... That means I would have to make a loop on world creation to loop through all the dirt turfs and drop the objs on that way?
I think I was wrong.

I just tested what you are doing; New() is called and the object is created.

You should put something in that empty switch() block or remove it entirely. That could be a problem. (Edit: It causes no problems, but still.)

Edit: Maybe something elsewhere in the source is interfering?
Hmm... yeah I double checked all that.. strange.
In response to Mitchy
What do both testing verbs look like?
basically same as original code, but using usr as a src...

Wondering if New() on turf has a problem with src.loc vars? not initialized yet?
New() really shouldn't have an issue creating objs on the turf. I'd try adding some debug output to world.log to see what's happening. Also remember if there's any turf on top of that dirt, then it's not really a dirt turf; the dirt is only an underlay, and it runs no New() proc.

For performance, it's really best if you actually put all of the code like this that you can into one proc that loops through the appropriate turfs, because of the proc call overhead.
Yeah I definitely did not put any underlays or overlays on the turfs...

I tried making a loop through the turfs, when would be the best time to call it?.. on World New() ?

Thank you FKI and Lummox JR for the help!
In response to Mitchy

I tried making a loop through the turfs, when would be the best time to call it?.. on World New() ?

What is it you are doing exactly? I have some ideas based on your original post but I want to be sure before I give my 2 cents.
Trying to make random objs spawn on certain turfs, which I also want to make procedurally to make randomly generated world... figure i'd work on just getting obj's to spawn on turf on world creation first lol
        test()
for(var/turf/T in world)
if(istype(T,/turf/dirt/))
usr << "[T.loc.x],[T.loc.y]"


this returns 1,1 for each dirt found... what am i doin wrong?! lol
Ahhh!! Strange. Okay that makes sense about why the new obj's didn't work.

How did you get around looping through and finding the coordinates of the turf?
This is false. Turfs do not behave like areas. Areas behave like areas. Areas such as T.loc.

Mitchy, could you show the code where you're creating the new turf?
Right now I'm just painting the turf on the map, here is the code for it... but like I think we've figured out, it returns 1,1 when I try to create the turfs in a verb through the loop above... so either way it's not working...

turf
dirt
icon = 'Turfs.dmi'
icon_state = "dirt"
New()
var occurence = rand(1,1000)
switch(occurence)
if(1 to 600)
new/obj/item/mineral/rock/small_rocks(src)

He is correct, I misread the code.
In response to Mitchy
Mitchy wrote:
this returns 1,1 for each dirt found... what am i doin wrong?! lol

T.loc is the turf's area, not the turf itself. The area's x,y,z vars are defined by the first turf (the one with the lowest ID) in it.

Turf IDs correspond directly to their position in the worldmap, so an area's "first" turf is the one with the lowest z, and of those the lowest y, and of those the lowest x.
Soo... you're saying its possible to loop though all the specific turfs and find the loc of that turf? Or I have to go about it in a different way?
In response to Mitchy
The coordinates of a turf T are T.x, T.y, and T.z.

The loc variable of objs and mobs on the map always refers to a turf.

The loc of a turf is always an area. The turfs themselves represent coordinates in the world.
OHH! DAMNIT. I'm an idiot. Why didn't I think of that... so simple.

turf
dirt
icon = 'Turfs.dmi'
icon_state = "dirt"
New()
var occurence = rand(1,1000)
switch(occurence)
if(1 to 550)
// nothing
if(551 to 750)
new/obj/item/mineral/rock/small_rocks(x,y,z)
if(751 to 850)
new/obj/item/mineral/rock/medium_rock(x,y,z)
if(851 to 1000)
new/obj/item/mineral/rock/large_rock(x,y,z)


https://gyazo.com/0fc00e6a9f7f6d7b58afc7cdc0ea1ac1

Works great now :)

Thanks everyone for the help!!
Page: 1 2