Exiting Functions: - SOLVED

Started by Fritos, Mon 12/07/2004 06:53:31

Previous topic - Next topic

Fritos

This is the code from After:

Code: ags

// 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 antispeed, 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 antispeed, 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.
}
}


I've got the fade in and fade out to work properly by importing the fuctions in my room script, but my problem is they continue to cycle once they have completed assuming because they are in my repeatedly_execute. What I would like it to do, is once it has reached its fade in and then fade out, I would like it to exit the function and continue with the code.

Barbarian

Could you make a variable that when it's a certain value, to run your "fading" part of the script, but upon completion, you change the variable so it will no longer be stuck on doing the "fading", but will then instead move onto the next part. Well, someone else who's more experienced with scripting can probably better explain what I mean.
Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

Fritos

#2
I figured it out.

In my room script:

Code: ags

if (IsObjectOn (1)==1){
FadeObjectIn(1, 1, 2);
FadeObjectOut(1, 1, 2);
ObjectOff(1);
}


I had it check to see if the object was on and then once it did its loop it turned off the object and stopped the continous loop. Now I don't know if this is the cleanest way to do this, so if anyone has a cleaner way of doing this, I would appreciate the input. Thanks.

SMF spam blocked by CleanTalk