The topic title might be a little bit misleading -- I know what Fibers are, and though I've never used them in my programs I know roughly how they're used.
What I'm confused about is "why?" Why would I use Fibers for anything? Is there some advantage to passing code off from one Fiber to another? I know Game_Interpreter makes liberal use of Fibers, but I haven't dug enough into the interpreter to really grasp how it's using them or why it would use them over anything else.
Thanks for any advice y'all can give.
as far as I know, they work like threads...
AFAIK normally you use multiple threads if you want your functions to work simultaneously with one another. It also keeps them independent, so you can pause one while the other is still running normally...
so maybe that's the same for Fibers...
Fibers do not run at the same time as the calling thread, that waits for the fiber to end. They can, however, be paused in the middle of processing. If you have a method, (assuming @fiber is your fiber variable)
def mythingy a = 6 @fiber.yeild a = 7 puts aendWe won't get to the last two lines until we call the fiber again. The Game_Interpreter uses them for a few reasons, one of the most important being the wait command. The Fiber is what makes the game, event, or common event wait when needed. This includes the actual wait command, or any command that has a wait option(change tint, etc).
You don't always need a fiber, but if you want to base your code on timing and waiting, a fiber may be the easiest way to go. I use fibers in a few of my own scripts, and once you figure them out initially, they're not so bad to use.
In addition to what is said, I'd look at how fibers are used throughout RM. I have some idea how threading works and why you'd do it (for like, parallel computing), but fibers appear to be used for a different purpose.
Thanks everyone. I don't have time to run your examples tonight Theodoric, but I will soon. Thanks for taking the time to write something up for this!