ID:145605
 
Code:
atom
var
health
attacking
mob
Dig
verb
Dig()
for(var/turf/T in world)
set name = "Dig"
set category = "Skills"
if(usr.attacking == 1)
usr << "Your still cooling down"
if(usr.attacking == 0)
if(T.name == "Dirtwall")
usr.attacking = 1
usr << "You starting to dig [T]"
T.health -= 1
Dirtcheck()
sleep(30)
usr.attacking = 0
mob
proc
Dirtcheck()
if(src.health <=1)
if(src.name =="Dirtwall")
src.icon_state = "dirt"
src.density = 0
else
..()

turf
Dirtwall
name = "Dirtwall"
icon = 'Tiles.dmi'
icon_state = "dirtwall"
density = 1
health = 3


Problem description:

In game when I dig its spamming the message Your still cooling down and when I remove that it doesnt check the dirt cause i can hit it 10000 times but it doesnt change

That's because you're putting it inside a loop. The "for(var/turf/T in world)" will cause everything indented under it to run once for each turf in the entire world! Which explains the spamming problem; you're getting sent that message for every single turf in the world (except for the first one, because the first time around it will set usr.attacking to 1 instead)!

There's another fundamental problem here though - Dirtcheck() is a mob proc, which means src is a mob, not the turf you're trying to dig! Yet you're treating it as if it is the turf.

In fact, nowhere do you actually figure out which turf you're digging. You need to resolve that, and then remove the loop, so that you're only digging one (player-specified) turf.

Probably the easiest method to figure out which turf you're meant to be digging is to put it as an argument to the verb, perhaps something like this:

Dig(turf/T as turf in oview(1))


That will allow the user to select any turf that they're next to for digging.

Then delete the "for(var/turf/T in world)" line, fix up the indentation for the lines that used to be underneath it, and make Dirtcheck() a turf proc instead of a mob proc. (The latter change will require you to call T.Dirtcheck() instead of plain Dirtcheck().)

Finally, instead of using "attacking==1" and "attacking==0", I recommend you use "attacking" and "!attacking" instead. This is a more robust method; you can read more about this here: http://byondscape.com/ascape.dmb/Wizkidd0123.2005-0129/ (scroll down to the bit labelled "The ! operator: A staple of robust coding").
In response to Crispy
Thanks a lot it really helped me and never knew you could use the "!" command for the 1 or 0 but thanks now i learned more =)
In response to BBDragoon
//Good  || Baaad
if(!var) if(var==0)
if(var) if(var==1)
var-- var-=1
var++ var+=1


Though, don't use the if(var) when you're assigning values such as 2, 3, etc. too.
In response to Mysame
Mmm now i got another question now when i dig it shows me the choice of Tile or Dirtwall but i only want it to do the dirt wall cause you standing on the tile(floor)

mob
Dig
verb
Dig(turf/T as turf in oview(1))
set name = "Dig"
set category = "Skills"
if(usr.attacking)
usr << "Your still cooling down"
if(!usr.attacking)
if(T.name == "Dirtwall")
usr.attacking = 1
usr << "You starting to dig [T]"
T.health -= 1
T.Dirtcheck()
sleep(20)
usr.attacking = 0
if(T.name == "Goldwall")
usr.attacking = 1
usr << "You starting to dig [T]"
T.health -= 1
T.Dirtcheck()
sleep(20)
usr.attacking= 0
In response to BBDragoon
You change the oview(1) to usr.loc
In response to Mysame
That doesnt work cause now it wont dig the wall infront of him anymore :S
In response to BBDragoon
For the wall INFRONT of him, you need get_step(usr, usr.dir)
In response to Mysame
Sorry, the following is not valid: Dirtwall.0x1001a7d
usage: Dig turf

mob
Dig
verb
Dig(turf/T as turf in get_step(turf, usr.dir))
set name = "Dig"
set category = "Skills"
if(usr.attacking)
usr << "Your still cooling down"
if(!usr.attacking)
if(T.name == "Dirtwall")
usr.attacking = 1
usr << "You starting to dig [T]"
T.health -= 1
T.Dirtcheck()
sleep(20)
usr.attacking = 0
if(T.name == "Goldwall")
usr.attacking = 1
usr << "You starting to dig [T]"
T.health -= 1
usr.gold += 150
usr.icon_state = "gold"
T.Dirtcheck()
sleep(20)
usr.attacking= 0
In response to BBDragoon
Now you're referencing from the turf, in the direction of usr's dir. I did say usr, usr.dir. I didn't say turf, usr.dir.
In response to Mysame
Mysame wrote:
> //Good  || Baaad>
var-- var-=1
> var++ var+=1


Those last two there are nonsense. var++ and var-- are no better than var+=1 and var-=1. I have seen several other people say that too, who is spreading this information?

++ and -- both have their practical applications, and they do not mean just "add or subtract 1". They are more complicated than that, as can be seen by the fact that such is not the only use of those operators. You can also do ++variable and --variable. These incremental and decremental variables are used when you want to adjust the timing of when they are incremented or decremented. One means "change before the statement it's in is evaluated" and the other means "change after the statement it's in is evaluated"
client/verb/test()
var/n = 1
src << n--
n = 1
src << --n

In the above example, even though n was the same going into each output line, you will not get the same output from them.

Of course, based on that description you can see the main purpose it has. That is, incrementing or decrementing a variable from inside another statement while using it.

n++ is no more robust than n+=1, indeed it does not even have the same purpose.
In response to Mysame
with usr it doesnt work neither i coppied the test version :S
In response to BBDragoon
BBDragoon wrote:
mob
> Dig
> verb
> Dig(turf/T as turf in get_step(turf, usr.dir))


Simple fix:
mob
Dig
verb
Dig()
set name = "Dig"
set category = "Skills"
if(usr.attacking) return
var/turf/T = get_step(usr, usr.dir)
...

You're trying to use an argument where you don't need one.

Lummox JR
In response to Lummox JR
You didn't define T!

Cheetoz: MYSAME
Pimpmas: rofl
Cheetoz: Lummox made a programming mistake
Cheetoz: http://developer.byond.com/forum/ index.cgi?action=message_read&id=431453&forum=3&view=0

Just HAD to do this ;)
In response to Mysame
Mysame wrote:
You didn't define T!

So I did not. Good call. Fixed.

Lummox JR
In response to Loduwijk
But it is shorter than +=1. I do think it looks better, too.
In response to CaptFalcon33035
CaptFalcon33035 wrote:
I do think it looks better, too.

I do too, but that's user preference. =)
In response to CaptFalcon33035
CaptFalcon33035 wrote:
But it is shorter than +=1. I do think it looks better, too.

It's also shorter than copytext, so maybe we should use it for that too.

Of course my above statement is an extreme overexaggeration, but still the point remains. Although ++ is shorter and easier to type and you may even think it looks better, it's not the same thing despite the fact it will work. And it is certainly not any more appropriate.