obj
End
Balloons
var
Money
Speed=10
Health
icon='Balloons.dmi'
density=1
Red
name="Red"
icon_state="Red"
Money=10

obj/Balloons/var/atom/Target

turf
Start
Water {icon='Turf.dmi';icon_state="Water"}
Density {density=1}
Grass {icon='Turf.dmi';icon_state="Grass"}

mob/verb/StartBalloons()
var/obj/Balloons/Red/R=new/obj/Balloons/Red
if(global.Round>0&&global.Round<5)
Spawn(R,10)

proc
Spawn(var/obj/Balloons/T, var/Count)
for(Count, Count >1, Count--)
if(T.name == "Red")
var/obj/Balloons/Red/R = new(locate(/turf/Start))
if(!R.Target)
for(var/obj/End/A in world)
R.Target = A
break
walk_to(R, R.Target)
world<<R
world<<R.Target
sleep(10)

var
Round=1

atom/movable/Move()
.=..()


That's my whole code, that's everything I've done coded so far.
In response to Flysbad
Flysbad wrote:
> mob/verb/StartBalloons()
> var/obj/Balloons/Red/R=new/obj/Balloons/Red
> if(global.Round>0&&global.Round<5)
> Spawn(R,10)
>
> proc
> Spawn(var/obj/Balloons/T, var/Count)
> for(Count, Count >1, Count--)
> if(T.name == "Red")
> var/obj/Balloons/Red/R = new(locate(/turf/Start))
>


Why are you creating a new balloon and passing it to Spawn just to check it's name and create another balloon? That's redundant. Just pass a text value to the proc instead of wasting space by creating a new object and not even deleting it.

>               if(!R.Target)
> for(var/obj/End/A in world)
> R.Target = A
> break
>


Now to this. Since you are creating a new balloon, it isn't going to have a target, is it? Instead of doing this every time, I would suggest doing this in the balloon's New() proc. Have it grab it's own target.

Also, you don't have to do in world. world is what is searched by default.

> atom/movable/Move()
> .=..()
>


Now why are you overriding Move() just to call it's parent function? Don't bother even using these lines unless you plan on modifying Move().

Just did some more research on this and found out the issue (Thanks go out to Keeth for using his master bug finding skills.).

walk_to() will not work if the target is too far away (world.view * 2 tiles away). walk_towards() does not have this restriction, which is why it works.

Either set your view higher or spawn the balloons closer to the target (Or use walk_towards()).

Another workaround would be to use a loop and use step_towards() each iteration. This would still let it account for obstacles, and the distance would not matter.
Page: 1 2