ID:149667
 
Ok I've got some of my own code to show now for random placement of turfs. The only problem now is I need to check to see if anything in the turf with the name other than "stars" is there if so it will use the continue command to skip it and not place anything there. I'm getting the following error for the loc.turf.name area.

error:loc.turf.name:undefined var
error::unknown variable type

LJR

UPDATE: I've now tested this code and it seems to work fine, just want to make checks so no other planets or other turfs are overlayed.



world/New()
var/i = 0
var/px, pz, pitem, loc
while(i <= total_planets)
px = (rand(1,500))
pz = (rand(1,500))
loc=locate(px,pz,1)
if(px > 239 && px < 261 && pz >239 && pz <261) continue
if(!istype(loc.turf.name=="stars")) continue
else
pitem = (rand(1,8))
switch(pitem)
if(1)
new/turf/planets/Class_M(loc)
i++
if(2)
new/turf/planets/Class_L(loc)
i++
if(3)
new/turf/planets/Class_V(loc)
i++
if(4)
new/turf/planets/Class_O(loc)
i++
if(5)
new/turf/planets/Class_K(loc)
i++
if(6)
new/turf/planets/Class_C(loc)
i++
if(7)
new/turf/planets/Class_U(loc)
i++
if(8)
new/turf/planets/Class_S(loc)
i++</261>
The massive switch() statement unnerves me a bit; it isn't necessary. For one thing, you've got i++ listed in every case, so it could clearly be done after the switch() and not in it.

Next, there's the istype() call in there: You've only got one argument, and it's completely wrong. I'd change the loc var to something more constructive like var/turf/T=locate(...), which guarantees you'll get a turf, and then you only need to check if T.name!="stars" or T.contents.len>0.

Back to the switch, I think you should set up a list of planet types and use that instead:
// this list var can be global too
var/list/planet_types=(/turf/planets/Class_M,
/turf/planets/Class_L,
/turf/planets/Class_V,
/turf/planets/Class_O,
/turf/planets/Class_K,
/turf/planets/Class_C,
/turf/planets/Class_U,
/turf/planets/Class_S)
var/ptype=pick(planet_types)
new ptype(T)
++i

Lummox JR
In response to Lummox JR
Ok I made the changes you suggested. One thing though I'm wonder does this code with the "continue" skip and still count as a i++ or will it break the while() statement?

if(T.contents.len>0) continue

LJR
In response to LordJR
LordJR wrote:
Ok I made the changes you suggested. One thing though I'm wonder does this code with the "continue" skip and still count as a i++ or will it break the while() statement?

In a for() loop like this...
for(i=0,i<5,++i)

...then the ++i would be executed. In a while() loop, continue always skips back to the beginning of the loop. The continue statement always skips over the rest of the code you write within the loop, and will only execute anything else if you've defined it as an integral component of the loop.

Lummox JR
In response to Lummox JR
cool then I got code now that is checking the space for its and if nothing is there placeing things there..

I should have 500 space stations, 250 planets in my game.
Since they're done dynamically its kinda hard to tell if its working right

LJE
In response to LordJR
You can check out my random map dealy for a kick it's a really fun little thing to mess with =P
In response to Nadrew
Thanks but I think I've got everything working fine, and it was my own code!!! I didn't see anyone else's demo or example!!! Just needed that check part to work was all.

LJR
In response to LordJR
I know you got yours working you should still look at mine it has some useful techniques that you can learn from it.
In response to Nadrew
cool.. I'll do that ;)

LJR
In response to Lummox JR
Lummox JR wrote:
Back to the switch, I think you should set up a list of planet types and use that instead:
// this list var can be global too
> var/list/planet_types=(/turf/planets/Class_M,
> /turf/planets/Class_L,
> /turf/planets/Class_V,
> /turf/planets/Class_O,
> /turf/planets/Class_K,
> ...


I'm curious, why not use typesof instead?
ptype = pick(typesof(/turf/planets)-/turf/planets)

/Andreas
In response to Gazoot
I was wondering about this also, typesof() is your friend, USE IT! icon_states() is also another friend use that too =P.
In response to Gazoot
Gazoot wrote:
I'm curious, why not use typesof instead?

Doh!
Much better idea, Gazoot.

Lummox JR
In response to LordJR
var/planets = 0
var/stations = 0
for(var/turf/T in world)
if(typesof(T,/turf/planet)) planets++
if(typesof(T,/turf/station)) stations++
usr << "There are [planets] planets and [stations] stations in the game."
But you probably figured that out already :oP
In response to Foomer
Foomer wrote:
if(typesof(T,/turf/planet)) planets++
if(typesof(T,/turf/station)) stations++

I think you mean istype().

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Foomer wrote:
if(typesof(T,/turf/planet)) planets++
if(typesof(T,/turf/station)) stations++

I think you mean istype().

Lummox JR

No, actually I meant ispath() :oP which is what I confused typesof() for. Ispath may be wrong too, but I don't feel like testing it to find out.