I see what you're saying now. You can get the thing to run and at the proper speed, but you want it to keep running beyond the detection distance. So if a hunter snuck up on something only a few meters away (the detection distance), then the animal might take off running for a few hundred meters.
Ok. So let's take a look at using the animalinfo#() array I was proposing.
remstart
`dim animalinfo#(number of animals,6)
the array will store information about the animal.
For this demo, we are only concerned about it running, so
the indeces are setup for that. You could very easily
include other parameters for walking speed, or eating,
or health, or anything you want.
animalinfo#(animal,0) == This is the running flag.
Set to 0 if the animal is not
running. Set to 1 if the
animal is running
animalinfo#(animal,1) == The animal running speed
animalinfo#(animal,2) == The animal detection distance
animalinfo#(animal,3) == The base distance the animal will run
away. I say the base distance because
we can add a random value to this so that
the animal might run a little further at
times.
animalinfo#(animal,4) == The random increment value to be added to
the base value. If you don't want any
fluctuation in distance, then this can be 0
animalinfo#(animal,5) == The max distance the animal will run. This
is equal to
animalinfo#(animal,3) + rnd(int(animalinfo#(animal,4))
animalinfo#(animal,6) == The current distance the animal has run. Each
time the animal stops running, set this to
0 .
remend
dim animalinfo#(25,6)
set up the specs for each animal
_main_loop:
do
for animal = 1 to number of animals
rem start by checking if an animal is already running
rem We can ahndle the result of this in a couple of different
rem ways. 1 way is to skip over any animals tha are already running.
rem The other way is to reset all of the values every time near is
rem flagged even if the animal is already running. I'll take
rem the first approach.
rem is the animal already running?
if int(animalinfo#(animal,0)) : `yes. Check it's distance and move it
move object animal,animalinfo#(animal,1)
rem add the distance it just moved to the total distance it has moved
rem so far
animalinfo#(animal,6)=animalinfo#(animal,6)+animalinfo#(animal,1)
rem now check it's distance
if animalinfo#(animal,6) > animalinfo#(animal,5) : ` did it run far enough?
`yes it ran far enough. reset a few array values
animalinfo#(animal,0)=0 : ` the animal is no longer running
animalinfo#(animal,6)=0 : ` reset the total distance it ran
endif
else
`No, the animal is not running yet
rem since the animal is not running, we now check it against near
calculate near
if near
rem set the running flag and the max distance
animalinfo#(animal,0)=1
animalinfo#(animal,5)=animalinfo#(animal,3) + rnd(int(animalinfo#(animal,4))
set the direction the animal will move
move the animal,animalinfo#(animal,1) :`the running speed
rem add the distance it just moved to the total distance it has moved
rem so far
animalinfo#(animal,6)=animalinfo#(animal,6)+animalinfo#(animal,1)
else
rem not near the animal and the animal isn't running
rem so do regular animal stuff
gosub _regular_animal_stuff
endif
endif
next animal
loop
The pseudo code above uses the array to store information about the running state of the animal. When animalinfo#(animal,0) is 1, the animal is running and we can skip the check for near which should save some time. Only the animals that are not running will be checked against near. The distance that the animal has run total since it started running is stored in animalinfo#(animal,6). That is compared to maximum distance that it can run which is stored in animalinfo#(animal,5) so we can stop it from running when it has gone that far.
This will allow you to have a detection distance and a max distance that the animal will run before it stops.
Enjoy your day.