ID:261569
 
Im stumped. Heres my problem for some reason my Worker walks to the Crystals but doesnt gather them.
Click()
for(var/mob/Worker/M in usr:units)
walk_to(M,src,1,M.speed)
if(M in view(1,src))
flick("cutting",M)
src.crystal-=1
usr:crystal+=1
sleep(M.speed*2)
the for Gets all the Workers that are selected and puts them in M. Then it tells them to walk to the crystalls at there M.speed till they are 1 away. Then for some reason it doesnt run the next if() statment which says when M is in view of src run the statments.

Could you tell me how to fix this problem so when the worker walks up it then runs the flick and minuses and adds the crystals. Then after that It runs the same thing over again till either all crystals have been mined or till the user clicks on a diffrent area.
Green Lime wrote:
Im stumped. Heres my problem for some reason my Worker walks to the Crystals but doesnt gather them.
Click()
for(var/mob/Worker/M in usr:units)
walk_to(M,src,1,M.speed)
if(M in view(1,src))
flick("cutting",M)
src.crystal-=1
usr:crystal+=1
sleep(M.speed*2)

I'm guessing the problem is that you are checking for distance before the mob gets to its destination. Try something like this:

mob/worker
var
owner // set this to the player who controls this mob
proc
get_crystal(obj/crystal/C)
flick("cutting",src)
C.crystal-=1
owner.crystal+=1
sleep(speed*2)

seek_crystal(obj/crystal/C)
while (!(C in view(1, src)))
step_towards(src,C)
get_crystal(C)

obj/crystal
Click()
for(var/mob/Worker/M in usr:units)
M.seek_crystal(src)


This is completely untested. Have fun!
In response to Skysaw
Yeah, I agree with Skysaw. I loathe walk_to. It just causes problems. I've never had problems with it, of course, because I've never used it, but I don't like it.
In response to Skysaw
When I click a crystal it quickly goes back and forth from being 1 space away from the crystal to where it was before. Have any ideas why it does this and how I could fix it?
In response to Green Lime
Green Lime wrote:
When I click a crystal it quickly goes back and forth from being 1 space away from the crystal to where it was before. Have any ideas why it does this and how I could fix it?

Is that with the code I posted?
In response to Skysaw
Skysaw wrote:
Green Lime wrote:
When I click a crystal it quickly goes back and forth from being 1 space away from the crystal to where it was before. Have any ideas why it does this and how I could fix it?

Is that with the code I posted?

Yea