I have some little questions about the use of "yield;" command. As I know, it is used to link the @MainLoop to other task.
1. Can 1 yield; command in @MainLoop be connected to all other yield; in tasks?
2. Can 1 yield; command in tasks be connected to all other yield;s?
3. Can I put a yield; command in @DrawLoop?
The word "link" isn't the best way to describe how yielding works. This is how tasks behave step by step. First take a look at this code:
@Initialize {
taskOne;
taskTwo;
taskThree;
}
@MainLoop {
yield;
}
task taskOne {
yield;
loop {
CreateShot01(GetX, GetY, rand(0, 5), rand(0, 360), BLUE01, 5);
loop(5){
yield;
}
}
}
task taskTwo {
loop(60){
yield;
}
// Create an effect or something, I dunno.
}
task taskThree {
loop {
CreateShot01(GetX, GetY, 3, GetAngleToPlayer, RED03, 10);
loop(12){
yield;
}
}
}
So first, when it goes into @Initialize, the first thing it does is go into taskOne. The very first thing is taskOne is a yield, which in a task means to pause the task until a yield is encountered outside of any task. Since taskOne is paused now, it continues where it left off in @Initialize and starts up taskTwo. The first thing in taskTwo is also a yield (or rather, 60 yields) so it pauses taskTwo and goes on where it left off in @Initialize again. Therefore it starts up taskThree, which finally doesn't have a yield in front so the script does something, fire a bullet at the player. After that, taskThree encounters a yield and so pauses itself like the other two tasks and goes back to where it left off, which is the end of @Initialize.
Since @Initialize is done, we go into @DrawLoop (yes @DrawLoop is first), but there is none so it goes to @MainLoop. @MainLoop has a single yield. This is the yield that I meant when I said that the tasks are paused until a yield is encountered outside of any task. At this yield, any task that has not finished yet will be continued in the order that they were started. In this example, none of the three tasks have finished yet (and really only one will ever finish because the other two are infinite loops) so it goes to the first task we ever started, taskOne and continues where it left off, the beginning of the infinite loop. It shoots a blue bullet at a random angle and speed before encountering a yield again. taskTwo gets another yield so it immediately repauses itself, and taskTwo also gets a yield so it immediately repauses itself. Now that all the tasks are either finished or repaused, it goes back to the @MainLoop past where the yield is. The MainLoop is done, so the game waits for 1/60 of a second and then loops back to the beginning of the @MainLoop. This continues over and over, resulting in a random bullet every 5 frames, an aimed bullet every 12 frames, and an effect created 60 frames after the start of the script.
As said earlier, you are allowed to put a yield in @DrawLoop as well, but it is not recommended. Since all commands that are supposed to be run in that frame when the tasks continue themselves will be piled into the @DrawLoop instead of the @MainLoop, many unexpected errors may occur. Also if you have a yield in @DrawLoop and in @MainLoop, since there would be two yields per frame, it would cause the script to run two times faster.
Warning - while you were typing 5 new replies have been posted. You may wish to review your post.
....lol