ID:168740
 
I hate for, the statement never works for me.

        New(client/c)
src.Bombs = rand(1,10)
for(/Minefeild/m in oview(0))
if(src.Bombs == 10)
new /turf/Mine/
del src


Code\Turf.dm:35:error:/Minefeild/m:undefined type path


Oh how I hate for statements.
First, on default, the first argument for New() is the location where you want to create it. You don't seem to even use it.

You need to define /Minefield/m. Assuming you defined the datum /Minefield, just add <code>var</code>. I can't really do much since you never specified whether it was a turf/obj/mob/area. I'll assume it's the pathtype of an obj.

src.Bombs = rand(1, 10)
for(var/Minefield/m in oview(0, src))
if(src.bombs == 10)
new /turf/Mine (src.loc)
del(src)


~~> Dragon Lord
For loops through a list. What you're looking for is an object, not a path. What you want is this:

for(var/Minefield/m in oview(0))

/Minefield/m is a path, like
Minefield
m
name = "an M-type minefield"

...which is obviously not what you wanted.
var/Minefield/m is an object, "m"

As an additional note, your "src" references are unneeded there. "src" is assumed if you leave the reference out. However, if it helps you understand your code better, I don't think there's any harm in being specific.

If you have difficulty with for() statements in the future, here's a quick workaround:

for(i in oview(0)) // or for(i in any_list)
if(istype(i,/Minefield))
//do the rest

for(i in list) will usually work.

Good luck and have fun with your explosives.
In response to Unknown Person
What im trying todo, is replace some of the minefeild with Mines, anyway to todo this?
In response to Strawgate
I say scrap that existing thing, since you can do it much better.

A nice way to do it is to create a turf called /turf/minefield. When it's created, a 1 out of 10 chance there'll be a mine in there. That's what you tried to do.

turf
minefield
New()
..()
if(prob(10)) // 10% chance
new /turf/mine (src)
mine
Entered(atom/movable/A)
if(ismob(A)) view(A) << "BOOOOOOM!!! YOU DIE AHAHA!"


Creating a turf on top of another turf automatically deletes the bottom turf.

~~> Dragon Lord
In response to Unknown Person
How do you set the name of a turf, without changing the actual name... like the name you see when your mouse is over it?
In response to Unknown Person
        proc/Surronding()
for(var/turf/Mine in oview(1, src))
src.Surronding += 1

How about that...

                if(src.name1 == "Minefeild")
spawn()Surronding()
if(src.Surronding == 1) src.icon_state = "1"
if(src.Surronding == 2) src.icon_state = "2"
if(src.Surronding == 3) src.icon_state = "3"
if(src.Surronding == 4) src.icon_state = "4"
if(src.Surronding == 5) src.icon_state = "5"
if(src.Surronding == 6) src.icon_state = "6"
else src.icon_state = "blank"


O.o Help?
In response to Strawgate
icon_state=surrounding?(surrounding):"blank"
Try that instead of that if statement. :|
In response to Ol' Yeller
Its not counted the mines near the minefeild like I want it too...
In response to Strawgate
Are you making its name1 Minefield?
In response to Ol' Yeller
Ol' Yeller wrote:
icon_state=surrounding?(surrounding):"blank"
Try that instead of that if statement. :|

You can't set icon_state to a numerical value. You have to use "[surrounding]" there instead.

Lummox JR
In response to Strawgate
name = ""
In response to Strawgate
Strawgate wrote:
>       proc/Surronding()
> for(var/turf/Mine in oview(1, src))
> src.Surronding += 1
>

How about that...

>               if(src.name1 == "Minefeild")
> spawn()Surronding()
> if(src.Surronding == 1) src.icon_state = "1"
> if(src.Surronding == 2) src.icon_state = "2"
> if(src.Surronding == 3) src.icon_state = "3"
> if(src.Surronding == 4) src.icon_state = "4"
> if(src.Surronding == 5) src.icon_state = "5"
> if(src.Surronding == 6) src.icon_state = "6"
> else src.icon_state = "blank"

O.o Help?

As for your loop, no. You are looking for a turf of type /turf/Mine in oview(1,src), but your code suggests that the loop takes into account all turfs in oview(1,src) with Mine as the reference var.

    proc/Surrounding()
for(var/turf/Mine/M in oview(1,src))
src.Surrounding += 1


Although things like 'src.Surrounding' could simply be shortened to 'Surrounding', and '+= 1' could be shortened to '++', so it might look like:

    proc/Surrounding()
for(var/turf/Mine/M in oview(1,src))
Surrounding++



As for the second piece of code...it makes no sense to me. You just randomly threw it in there.

If src.Surrounding is always going to be a value of 1-6
- You could simply say that src.icon_state = "[src.Surrounding]"
If src.Surrounding will have values 0-6 (0 corresponding to the else clause)
- You could change the blank icon_state name to 0, then use src.icon_state = "[src.Surrounding]"

You could, of course, throw in checks to make sure that they always have certain values:

        if(!isnum(Surrounding)||Surrounding>6||Surrounding<1)
Surrounding = "blank"
icon_state = "[Surrounding]"


If you do need to separately check your values, however, don't use back-to-back if statements. Each if statement must be processed. On the other hand, a switch statement is only processed once:

        switch(Surrounding)
if(1)
icon_state = "1"
if(2)
icon_state = "2"
if(3)
icon_state = "3"
if(4)
icon_state = "4"
if(5)
icon_state = "5"
if(6)
icon_state = "6"
else icon_state = "blank"


Hope that helps, some.

Hiead