Yeah, Rand() is defined as int but returns a float. Good catch.
Here is a cleaned-up version that does what you want. Note that the ffc will probably fly off the screen, since there is no bounds checking. Don't forget to pass in the ffc number with D0.
Code:
import "std.zh"
ffc script pathTest{
void run(int this_ffc_num)
{
// "this_ffc->" bug workaround
ffc this_ffc = Screen->LoadFFC(this_ffc_num);
while(true)
{
int best_dir = Floor(Rand(4))+1;
//routine to move FFC in chosen direction
if(best_dir==1)
{
for(int n=0 ; n<4 ; n++)
{
this_ffc->Y-=4;
Waitframe();
}
}
else if(best_dir==2)
{
for(int n=0 ; n<4 ; n++)
{
this_ffc->X-=4;
Waitframe();
}
}
else if(best_dir==3)
{
for(int n=0 ; n<4 ; n++)
{
this_ffc->Y+=4;
Waitframe();
}
}
else if(best_dir==4)
{
for(int n=0 ; n<4 ; n++)
{
this_ffc->X+=4;
Waitframe();
}
}
else
{
Waitframe();
}
}//ends while true
}//ends void run
}//ends pathTest
If you don't want it to fly off the screen, I would suggest adding some ifs like so:
Code:
for(int n=0 ; n<4 ; n++)
{
if(this_ffc->Y < 4)
{
this_ffc->Y+=4;
}
else
{
this_ffc->Y-=4;
}
Waitframe();
}