ID:171308
 
How do i make a mob that can move around on its own like random?
Yes, using step_rand().
In response to DeathAwaitsU
that doesnt work lol
    Blue
icon = 'Ghostys.dmi'
icon_state = "Blue"
step_rand()
In response to Strawgate
Learn how to use procs and look up step_rand.
In response to DeathAwaitsU
I got this, my friend helped me its error free but the npcs dont move....
mob
Blue
icon = 'Ghostys.dmi'
icon_state = "Blue"
density = 0
proc/Wander()
while(src)
step_rand(src)
In response to Strawgate
Firstly, put a sleep in that thing.
proc/Wander()
while(src)
step_rand(src)
sleep(1)

Secondly, you need to call it in the object's New function.
mob/Blue/New()
spawn()Wander()
In response to Loduwijk
Loduwijk wrote:
Firstly, put a sleep in that thing.
> proc/Wander()
> while(src)
> step_rand(src)
> sleep(1)
>

Secondly, you need to call it in the object's New function.
> mob/Blue/New()
> spawn()Wander()
>




like tis?
proc/Wander()
while(src)
step_rand(src)
sleep(1)


mob
Blue
icon = 'Ghostys.dmi'
icon_state = "Blue"
density = 0
spawn() Wander()
</dm>cause that aint working
In response to Strawgate
I find that using while() like that causes great CPU usage, why not re-call the procedure instead?
In response to Strawgate
Ok you don't seem to understand a KEY POINT.

mob
Test
icon = 'test.dmi'
step_rand(src)


NO!

You can't do that! EVER!

You can't call processes like you define variables(such as the icon, hp, icon state etc etc).

You can do this however:

mob
Test
icon = 'test.dmi'
proc/Move()//first you name a new process(proc)
while(src)
sleep(10)
step_rand(src)


That's how you make a proc with information to do something, the while(src) and sleep(10) mean as long as the mob exists, wait 1 second and then call step_rand for the mob.

Now if you need a way to make the mob actually USE that proc, you need a way to call it. The most effective way in this case would be to do this:

mob
Test
icon = 'test.dmi'
proc/Move()//first you name a new process(proc)
while(src)
sleep(10)
step_rand(src)
New()
//again we're using a proc, but this one is predefined by the developers of BYOND and is always called when the mob is created.
spawn() src.Move() // calls the Move proc defined above.


You need to understand you can't put commands where you define variables like icons.
In response to Crashed
ok i got it now.... how do i make it so no one can move on diaganols?
In response to Strawgate
For NPC's, you'll need to use lists and the pick() proc to pick from the list and move the NPC in that chosen direction.

var/list/directions = list(NORTH,SOUTH,EAST,WEST)
var/A = pick(directions)
step(src,A)


Look up lists, pick and the step commands instead of using copy and paste.

As for the client, as soon as the diagnol proc is called, we'll end it.

client
Northwest()
return //end the Northwest movement.


Do the same for NE,SW and SE.

In response to Crashed
I have not clocked both to see which is actually faster, but I assume that continually looping using while is faster than recusively calling a function from itself. Having it call itself creates a small amount of overhead, whereas continuously looping with while just keeps doing the same thing over without the extra calculations needed to call a function.

Byond needs a function that allows you to see exactly how long it is between two points in time. That would make it much easier to clock various code designs. In fact, I will go suggest that in the Q&A right now. That would be great.