It's a classic state-machine problem. There are two states, wandering and chasing, and there are conditions to move between these.

So we need a variable that defines the state. Say we call it Slimestate. You decide the exact conditions. For example 1=wandering, 2=chasing.

Now you make your blocks to have an endless loop, within them an if then-else. If state=1 then it does the wandering code, if it is 2 it does the chasing code.

Then you go to the conditions. If it is close, it has to go into chasing mode. But it should only do that once: so we need something to monitor when this "collision" happened. Say we introduce a variable "chasetime". We make it 0 on boot.

In block-code you can make a separate "watchdog". It has to do the following (pseudocode):

- Code: Select all | TOGGLE FULL SIZE
`On start`

Loop forever

If slime is nearby AND chasetime=0 then

slimestate becomes 2 (chasing mode)

chasetime becomes 300 (frames)*

easetime becomes 60 (I explain this part later)

* check how fast a routine is called, I guess 30 or 60 times a second.

You make a second watchdog that subtracts 1 from chasetime if it is greater than 0 and that when it is 0 the slimestate becomes 1 again.

- Code: Select all | TOGGLE FULL SIZE
`On start`

Loop forever

if chasetime>0 then

subtract 1 from chasetime

if chasetime=0 then

slimestate=1

Now there is a possible situation that messes up: if slime is still nearby, it will immediately jump to chasemode once more. So we also need easetime.

On start make easetime=0

So if me make chasetime 300, we also make easetime 60 (2 seconds to escape).

The second watchdog has to be altered a bit:

- Code: Select all | TOGGLE FULL SIZE
`On start`

Loop forever

if chasetime>0 then

subtract 1 from chasetime

If chasetime=0 then

if easetime>0 then

subtract 1 from easetime

slimestate=1 (wander)