ID:142071
 
Code:
turf
grass
icon = 'preset.dmi'
icon_state = "grass"
name = "grass"
New()
icon_state = pick("grass","grass2","grass3","grass4")
dirt
icon = 'preset.dmi'
icon_state = "dirt"
New()
var/dcount = 0
var/list/otherturfs=new()
for(var/turf/dirt/T in orange(1,src))
dcount++
for(var/turf/B in orange(1,src))
if(B != /turf/dirt)
otherturfs+=B
while(dcount << 2)
var/picked=pick(otherturfs)
new/turf/dirt(locate(picked))
dcount++


Problem description:
Now, I'm playing around with turfs, so don't ask me what in gods name am I doing with that code. I'm trying to make it so when a dirt turf is created it checks its range for anything that isn't a dirt and uses it as a suitable target for place its dirt brethren until it has enough dirt around it to be happy. However, I haven't seen... any results. At all. I'm probably just doing something stupid and not realizing it. Also, I have tried multiple ways of locating the new dirt, such as using the location of the picked turf but nothing is working.
Bah.
I don't get what your doing exactly, but << is the bitwise (left or right? left I guess) shift operator, not less than. < is less than.

EDIT: You can also use istype() instead of type ==

EDIT#2: Using less than in your while loop will crash the game if you keep increasing dcount.
In response to Jeff8500
Jeff8500 wrote:
I don't get what your doing exactly, but << is the bitwise (left or right? left I guess) shift operator, not less than. < is less than.

EDIT: You can also use istype() instead of type ==

EDIT#2: Using less than in your while loop will crash the game if you keep increasing dcount.

Hrm, I'm used to coding with a different language. I'm very rusty with DM coding. In any case, I don't quite get your logic with my dcount. If it's not less than 2 then shouldn't the while loop end? I mean, that is why while is while. I tried changing that << into < and checking for errors, but I'm not really seeing anything =\. Bah, this is painful.

If you're wondering what I'm trying to do, I'm running a couple of tests to see if I can't get turfs to do what I tell them to do. That sounds a little weird but meh.

As for this particular bit of code, the dirt is supposed to 'scan' in one range around it. If there isn't enough dirt turf in its immediate area, it's supposed to call the while loop to make more while the count of dirt in the immediate area is still less than what is predetermined.
In response to WarLin
No, it says while dcount is less than two, execute the below code, not while dcount isn't less than two (greater than).

I noticed you said if B != /turf/dirt. That's improper; B is a turf, and not a type path. If you're that rusty, maybe you should read through the DM guide.

Either way, it should look more like this:

#define DANT 3
//Stands for Dirt area number thing >_>

turf/dirt/New()
var/list/notdirt = new
var/dcount
for(var/turf/T in oview(1))
if(istype(T,/turf/dir)) dcount++
else notdirt += T
while(dcount < DANT)
var/picked = pick(notdirt)
notdirt -= picked
new /turf/dirt(picked)
dcount++

In response to Jeff8500
Jeff8500 wrote:
No, it says while dcount is less than two, execute the below code, not while dcount isn't less than two (greater than).

If dcount is greater than then the while ends. So while dcount is lower than two it still executes, once it goes above, the while exits. You're over complicating things.

I noticed you said if B != /turf/dirt. That's improper; B is a turf, and not a type path. If you're that rusty, maybe you should read through the DM guide.

Either way, it should look more like this:

> #define DANT 3
> //Stands for Dirt area number thing >_>
>
> turf/dirt/New()
> var/list/notdirt = new
> var/dcount
> for(var/turf/T in oview(1))
> if(istype(T,/turf/dir)) dcount++
> else notdirt += T
> while(dcount < DANT)
> var/picked = pick(notdirt)
> notdirt -= picked
> new /turf/dirt(picked)
> dcount++
>

I'll take into advice that I need to use istype, but it doesn't seem like I need to define anything extra =\. Much less make an unneeded constant.

Thanks for your help though, It's appreciated.

Here's the revised code if anyone cares :
    dirt
icon = 'preset.dmi'
icon_state = "dirt"
New()
..()
var/dcount = 0
var/list/otherturfs=new()
for(var/turf/dirt/T in orange(1))
dcount++
for(var/turf/B in orange(1,src))
if(!istype(B,/turf/dirt))
otherturfs+=B
while(dcount < 2)
var/picked=pick(otherturfs)
otherturfs -= picked
new /turf/dirt(picked)
dcount++

It works. Well.
Too well.
In response to WarLin
Note that << will make the value bigger for a certain amount of time (depends on the value of the variable you're shifting). It also will never terminate, as that loop is always going to be true ('cause you're not assigning a value).
In response to WarLin
The second loop is just wasting CPU; you're calling if(istype()) anyway, so the little else is good.
In response to Jeff8500
Oh holy crap.
I just got that.
Damnit ;_;.
Sorry for that.
Anyways, again, thanks for the help.
edit:
Before, the new() proc only worked as the whole
world started, now it only works when I individually
spawn dirt. Hrm.