Nice, but a bit risky as is

If rate doesn't divide 100, then you'll overshoot the test values.
Modified version.
[code]
// objectnum, object to fade in or out.
// antispeed , 1 = fastest, 5 = slowest
// rate (transparency), 1 = slower, 20 = faster, 100 = immediate
function FadeObjectIn(int objnum, int speed, int rate) {
int trans = 100; // object initially invisible
while (trans > 0) { // as long as object hasn't fully faded in
trans = trans-rate; // subtract from transparency percentage
if(trans<0){trans=0;}//guarantee exact at finish.
SetObjectTransparency(objnum, trans); // change the object's transparency
Wait(antispeed); // pause.
}
}
function FadeObjectOut(int objnum, int speed, int rate) {
int trans = 0; // object initially visible
while (trans < 100) { // as long as object hasn't fully faded out
trans = trans+rate; // subtract from transparency percentage
if(trans>100){trans=100;}//guarantee exact at finish.
SetObjectTransparency(objnum, trans); // change the object's transparency
Wait(antispeed); // pause.
}
}[/code]
This assumes that the object transparency is already set at the initial value. e.g. Whatever is to fade out is fully opaque (0% transparent) before the function is called.