ID:141457
 
Code:
turf
Click()
for(var/mob/Unit/M in world)
if(M.owned==usr)
if(M.selected==1)
walk_to(M,src,2)
..()


Problem description:
The code above seems right to me, Making a Selected Soldier move to the Turf Clicked.
But it doesn't, Any idea why? I'm tired right now so I'm probably just overlooking something.

Mickemoose wrote:
Code:
turf
> Click()
> for(var/mob/Unit/M in world)
> if(M.owned==usr)
> if(M.selected==1)
> walk_to(M,src,2)
> ..()
>

Problem description:
The code above seems right to me, Making a Selected Soldier move to the Turf Clicked.
But it doesn't, Any idea why? I'm tired right now so I'm probably just overlooking something.

I would probably do it as follows:

mob/Unit
Click()
usr.selected = src

turf
Click()
if(usr.selected)
walk_to(usr.selected,src,2)
usr.selected=null
else return
<dm>

I jsut tested this out and it works fine, so you should be able to use it for what you need. It is also more efficient.
In response to Satans Spawn
Great! It works.
Thanks.
In response to Mickemoose
Not a problem, good luck with your game.
In response to Satans Spawn
That's probably bad because now anything the usr selects will try to walk which could cause future runtime errors.
In response to Spunky_Girl
Spunky_Girl wrote:
That's probably bad because now anything the usr selects will try to walk which could cause future runtime errors.

It will only select Units. Notice how the Click() proc is under mob/Unit. Just to make sure, I even just tested it. It will not select anything but the Unit type.
In response to Satans Spawn
Aha! I'm blind! :D Either that or you're very sneaky with your snippets :o
In response to Satans Spawn
What would be better is a list, and to run a for() loop through the list just in case there are more units to be selected than 1.