Ruby/RGSSx questions that don't deserve their own thread

Question(s) of the day...

What is a Fiber and how can i yield one ?
That's a pretty general question maybe you can provide a specific example you are having trouble with.


You create a fiber, give it some instructions to run, and then let it run concurrently.


If you want the fiber to pause for awhile, you tell it to yield and then it will wait until you tell it to resume.


You probably ran into issues like "yielded from main fiber" when trying to yield a fiber.
Hello - Im a RPG maker newbie. I was wondering if there was a way to have multiple sound effects sit in a 'bank' together. So that each time a sfx is triggered, a different audio file from the bank is played.

So for example, rather than choosing 1 sfx that plays when an enemy attacks, I could choose, say 10 sfx, one of which will play after each attack.
Question(s) of the day...


What is a Fiber and how can i yield one ?
I know Tsukihime already answered this, but I thought that the answer could use some more explanation. Fibers are... relatively obscure, honestly, but what they do is essentially store code to be run that can be passed back and forth from the Fiber to whatever called it. When you create a new instance of the Fiber class, you pass it code to run -- usually in the form of a block, but not always. Once the Fiber is created, it does... absolutely nothing. In order to get the Fiber to do anything, you have to call the resume method on it, which will begin running the Fiber from the beginning of the code block passed to it. From there, the Fiber will continue to run this code until the end of the code block or until a call is made to Fiber.yield. When you call that, control is passed back to the caller of the Fiber until the resume method is called on the Fiber once more, at which point it picks back up where it left off (and the cycle continues).


In VX Ace, Fibers are used in Game_Interpreter and Window_Message to control when code is run, basically. Each Game_Interpreter has its own fiber that is used to control when its code is to be executed (pausing it under a number of circumstances, such as screen changes or when the message window is processing). Window_Message uses it similarly, but mainly to control when text processing is done.


Honestly, though, there's very little need for much of anyone scripting for RPG Maker to make use of Fibers. Why the interest in them, if I may ask?
i recently wrote a fog system, where i have limited the amount of fogs to 3, i done this by basically copying all methods used in a standard parallax , and creating a new sprite class that holds my "fog movement" (ect )info 

i was just looking through the default scripts and noticed Game_Pictures runs using fibers and i figured the next improvement to my fog script could* be replicating the structure of something like Game_Pictures, passing the method through $game_map.screen ect but making the code show a designated fog rather than picture 😛

also ty for both replys , they helped me understand a little better 🙂
Game_Pictures doesn't use fibers. Game_Pictures is a wrapper to Array and the "yield" you see is a Ruby keyword, used to invoke the block passed to the original array method "each" to the wrapper's "each".
Game_Pictures doesn't use fibers. Game_Pictures is a wrapper to Array and the "yield" you see is a Ruby keyword, used to invoke the block passed to the original array method "each" to the wrapper's "each".
Im sorry but ive read and re-read these lines about 20 times 

if i understand correctly then all Game Pictures allows is for a data block to be specified ? 

and the yeild just allows for the data specified to be matched into the origional data block?
Blocks are things I rarely see explained well, and to be honest, I'm not sure if I can do any better.
 
Look at Game_Pictures. You only see 3 methods: initialize, [] and each. If you look carefully, you notice that the Game_Picture objects aren't stored in Game_Pictures itself, but in the instance variable @data, which is an array.
 
To iterate through an array, you have the method each:
 

ary = [6, 8, "test"]ary.each {|val| puts val}=> 6=> 8=> "test" 
Now look at the each method of Game_Pictures:
 

def [email hidden] {|picture| yield picture } if block_given?end 
It exists so instead of accessing directly @data and call @data.each, you call the each method of Game_Pictures instead:
 

each {|pic| do_stuff_here} 
So, this block above will be passed to @data (well, @data.compact in fact, but it doesn't matter right now) and the yield keyword with replace |pic| with |picture| instead.
ok i think i get it , you done a real good job of simplifying it for me, thanks 🙂  i may have to do some messing around with it to see if i can find any benefit to doing things that way. if i get stuck il search some ruby forums, i dont wanna divert this thread 🙂

thanks again
I'm having troubles using eval. I want to run something like this to see if I'm on a certain map:

@cond = '$game_map.map_id == 52'return eval(@cond)I would expect the result of that would be true when I'm on map 52, and false when I'm not. But it's returning true every time.

If I add this line to output to the console:

p 'evaluating: ' + @cond+ ' (' + (eval(@cond) ? 'true)' : 'false)')it gives me the following:

"evaluating: [\"$game_map.map_id == 52]\"] (true)"I DID have this working when I was using XP, but it's not working in Ace. Any ideas?
Stab in the dark here but try removing the ' ' from it so it's:

@cond = $game_map.map_id == 52Then just don't evaluate it. It should save itself as a boolean.

Perhaps you could answer my question as well Shaz. I saw you asked about it on the "Interpreter Script Calls Event Equivalents" thread.
No, for my purposes, it MUST be a string - that's why I'm using eval in the first place. It doesn't get in there exactly as an assignment like I've shown above, but I do have a string with that comparison text inside it. Docs say eval evaluates a string expression and returns the result.

Someone else asked me about that choices thing just a couple of days ago. When it was originally posted, I thought I'd have a use for it, but I haven't reached that part of my game yet, so I haven't experimented with it. Tsukihime seems to think it will be more difficult to do because you can't be sure what's going to be in @indent (and it's not, as you think, the index of the choice the player makes). I just haven't had the need, or the time, to work on it further.
Shaz: The above code works for me. When I am at map id 4 for example it return true and otherwise false.
If it's suppose to be a string you evaluate then yeah, it should be correct.

If it's continuously returning true then you may have a script conflicting with the functionality of map id.

Have you tried printing the map ID?
No, for my purposes, it MUST be a string - that's why I'm using eval in the first place. It doesn't get in there exactly as an assignment like I've shown above, but I do have a string with that comparison text inside it. Docs say eval evaluates a string expression and returns the result.
I am not having any issues with it either.


I replaced 52 with 2. On map 1 it returns false, on map 2 it returns true.


I tested it from an event script call though, so don't know if that makes a difference.
That's very weird. If I use it in a script call, it works, but in my actual script it doesn't. There is no conflict with map_id. If I print that out on the previous line, it gives me the correct value.


I'll tinker with it a little, and if I can't get it working I'll start a new thread.


What version of Ace are you guys all running? Mine is 1.01a


Edit: I think I found the solution ... I was using command.parameters.to_s instead of command.parameters[0].to_s - changing that got me a little further, now I just have to figure out how to fix the clash between this script and another, 'cause I don't want to give either of them up 🙁
How do i know if my RegExp is "fast" (efficient) or not ?

Heres a few different regexp's i use ...

/<(?:SHOW BG|SBG):[ ](.*)>/i/<(?:NAME POS|NP):[ ](\d+),[ ](\d+)>/i/<(?:MAP NAME|MNW)>([^><]*)<\/(?:MAP NAME|MNW)>/im
Also how would i write a regexp that ignores spaces ?

basically like this one... ( im sure that the below regexp ignores spaces)

/<(?:BADGES|badges):[ ](\d+(?:\s*,\s*\d+)*)>/i
but with a limit on how many times the note can be split ?
Guys there's this template made in Ruby (not in RGSS API) format, wherein its mainly like RPG Maker XP.

It has been widely spread I guess, using Library Gosu for Ruby. So using some RGSS conversion to it would be very nice!
Also how would i write a regexp that ignores spaces ?


basically like this one... ( im sure that the below regexp ignores spaces)

/<(?:BADGES|badges):[ ](\d+(?:\s*,\s*\d+)*)>/ibut with a limit on how many times the note can be split ?
Regex is very simple you can't keep track of things like number of times something occurs without using helper functions in ruby.


Though I'm not sure why you would need to do it.

Guys there's this template made in Ruby (not in RGSS API) format, wherein its mainly like RPG Maker XP.


It has been widely spread I guess, using Library Gosu for Ruby. So using some RGSS conversion to it would be very nice!
It's another library for game development, not a template.
Is there a way to call the Continue/Load screen like one would call the save screen?  I looked through the help file, but thus far I've come up with nothing. OTL

EDIT: NEVER MIND I FIGURED IT OUT

after much trial and error, I threw this in a Script call event thing:

SceneManager.call(Scene_Load)and then everything was great.

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/