Understanding Fibers

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. 
Try to put this code in your script list.

Then do a playtest. Don't forget to see the RGSS console output.

def run Fiber.yield 1 Fiber.yield 2 Fiber.yield 5 Fiber.yield "hello world" Fiber.yield :hello_worldenddef updates Graphics.update Input.update puts $fiber.resume if Input.trigger?🙂C)end $fiber = Fiber.new { run }updates while trueYou will know everytime you press the confirm button, the RGSS console showing the result.

Or you can insert this code instead.

def run text = "This is just a sample text for " + "fiber testing.\nSo I make it very " + "loooooong so \nit may take a long time. " + "dsadsadsadsad\nsadsadasdsadsaddsadsadsadsad" index = 0 loop do Fiber.yield text[index] index += 1 endend def updates Graphics.update Input.update print $fiber.resumeend $fiber = Fiber.new { run }updates while trueThe RGSS console now will run just like the game message windows

Reference : http://theolized.blogspot.com/2013/08/ruby-fiber-explanation.html (Sorry, but it's in Indonesian)

Edit:

I just give a little example how Fiber works. And how to use Fiber.

Trust me, Fiber is an awesome class that should be used optimally
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!

Original thread: https://forums.rpgmakerweb.com/threads/understanding-fibers.19259/