Animating objects

Kon-Tiki Does anyone know if it's possible and, if it is, how to randomly animate an object? I'm trying to make someone who stands still, do the same action at random.

For example: A bird stands on some hay. It should start picking in the hay at random.

If it isn't possible, then does anyone know how to (again, an example) make two birds (the same views) pick the hay on different moments?
jelleghys You'll have to make two (or more) loops
Loop no 0: bird does nothing
Loop no 1: bird does animation

Then:


#define bird o1
#define bird_is_doing_animation f100
#define bird_end_of_loop f101

//blabla
animate.obj(bird);
set.view(bird,no);
//blabla


if (!isset(bird_is_doing_animation)){
random(0,20,v100);
if(v100==0){
set(bird_is_doing_animation);
set.loop(bird,1);
set.cel(bird,0);
start.cycling(bird);
end.of.loop(bird,bird_end_of_loop);
}
}

if (isset(bird_end_of_loop)){
reset(bird_is_doing_animation);
set.loop(bird,0);
}

//blabla

return();


So the first if-block picks a random number between (inc.) 0 and 20.
When the random number is 20 (1 chance out of 21) the bird object will be set in loop number 1 and animate until it reaches the last cel (bird_end_of_loop will then be set).
The second if-block will test if bird_end_of_loop is set, if so, it will reset the bird_is_doing_animation flag and put the bird back again in loop number 0.



Something like that???
jelleghys The bird_is_doing_animation flag is necesary if you don't want the bird-animation being set up when the bird is already being animated...

Of course, if you want the bird being animated more often, you'll have to change the 20 in the random-thing:

random(0,20,v100); => 1 chance out of 21
random(0,100,v100); => 1 chance out of 101
random(0,10,v100); => 1 chance out of 11
Kon-Tiki Hmmm, this isn't quite what it should be. This is a random event every time you enter the room. It should be a random event in the room (so it happens more than once when you're in the room.)

Consider it as a bird which is looking around for food (while standing still), and, when it thinks it has found something, it should try and eat it, just to restart this from the beginning when finished.

jelleghys If you put the 2 if-blocks AFTER the if(isset(f5)){}block, the animation will occure (at random) more than once in a room (without leaving the room)...


#include "defines.txt"
#define bird o1
#define bird_is_doing_animation f100
#define bird_end_of_loop f101

if (isset(new_room){
//blabla
animate.obj(bird);
set.view(bird,no_of_view);

//blabla
}


if (!isset(bird_is_doing_animation)){
random(0,20,v100);
if(v100==0){
set(bird_is_doing_animation);
set.loop(bird,1);
set.cel(bird,0);
start.cycling(bird);
end.of.loop(bird,bird_end_of_loop);
}
}

if (isset(bird_end_of_loop)){
reset(bird_is_doing_animation);
set.loop(bird,0);
}

//blabla

return();

Kon-Tiki :) Thanks :) It's working perfect now.
Joel You should probably reset the bird_end_of_loop flag inside

if (bird_end_of_loop)

so that you code doesn't keep setting the bird's loop to 0. It probably won't hurt it to leave it as it is, but it's a little cleaner, and besides...resetting the flag will keep you in the habit of resetting flags with end.of.loop which will help you avoid bugs later on.
jelleghys Good remark!

If it isn't possible, then does anyone know how to (again, an example) make two birds (the same views) pick the hay on different moments?


If you want the birds picking hay on different moments (not random), you just have to set different cels to start with:


#define bird_1 o1
#define bird_2 o2

if(isset(new_room)){

//blabla
set.cel(bird_1,0);
set.cel(bird_2,2); // assuming you have at least 3 cels in this loop
//blabla
}



But after all, I think the random stuff is much nicer to look at. This thing above will probably look very unnatural.
Kon-Tiki Thanks, the random works fine now, but I have another problem. The wander doesn't work.
Here's my logic:

#define kapitein o1
if (isset(f5)) {
load.pic(v0);
draw.pic(v0);
discard.pic(v0);
set.horizon(37);
}
draw(o0);
show.pic();

   animate.obj(kapitein);
   load.view(4);
   set.view(kapitein,4);
   position(kapitein,81,85);
   draw(kapitein);
wander(kapitein);

if (v2 == 2) {
new.room(3);
}
if (v2 == 4){
new.room(5);
}
return();

// Messages


What this gives, is the same as Bug in Tryout. The captain walks at the same spot as where he is positioned, but he doesn't change direction or move from that spot.

Does someone know how to fix this?
Joel If that is a direct copy of your code, then the problem is that the code to position the "kapitein" object is outside of the new_room block. Change your code so it looks like this:


#define kapitein o1
if (isset(f5)) {
load.pic(v0);
draw.pic(v0);
discard.pic(v0);
set.horizon(37);

animate.obj(kapitein);
load.view(4);
set.view(kapitein,4);
position(kapitein,81,85);
draw(kapitein);
wander(kapitein);

draw(o0);
show.pic();


}

if (v2 == 2) {
new.room(3);
}

if (v2 == 4){
new.room(5);
}
return();

// Messages
Kon-Tiki Thanks. (Seems like I make a lot of these mistakes ::), but now I'm getting the hang of it.)