Search the Community
Showing results for tags 'looping'.
Found 5 results
-
I've recently came across a code excerpt that piqued my interest. # Taken from Ace Equip Engine, Yanfly Engine Ace# All credits and copyrights where they due.8.times {|i| draw_item(0, line_height * i, i) } The syntax above essentially repeats the instructions in the block given after the times method call as much as 8 times. If we define this code using a for loop, an equivalent would be: for i in 0..8 do draw_item(0, line_height * i, i)end Then a question arose on my mind. Which would be better and why? Let's consider the pros and cons of both code structures. First one is the times function. This function actually calls for an iterator block, requiring evaluation, as it defines a yield clause in its definition. It basically repeats the instructions in the iterator block, yielding a local variable to signal how many times the iteration had performed, as much as n times, where n is the said number. 8.times would mean 8 times. A consideration would be if the number is not a number literal, but is a variable that contains a numeric value. Fine, we can use to_i to convert non-integer to integer values, but what if the variable ends up being a negative number? exa = 0exa -= rand <= 0.5 ? 1 : -1# ...# at this point, exa would contain either positive or negative number, and we want to perform a loop# of instruction for exa times.exa.to_i.times do |ex| puts ex + "\n"end The RPG Maker VX Ace help files mention that if the instance variable that calls the times function is a negative number, it does nothing. It doesn't matter if we mean to check for negative variables, since we can simply just exa.abs.to_i.times do |ex| things out, but if we meant to do a loop (say, if exa is 2, then we want a loop 2 times, as do if exa is -2, and using abs function is tedious in your opinion), in such cases, the for loop is handy. exa = 0exa -= rand <= 0.5 ? 1 : -1# blablablafor ex in 0..exa do puts ex + "\n"end This way, whether exa is positive or negative, the loop will still perform its job. The downside of a for loop is that while iterator expressions introduces a new block scope for local variables (and thus, we can perform wider range of actions inside the block scope), for loops doesn't introduce such scopes, and so, for has no effects on local variables. Basically, we would say that the following two loops will output the same. 8.times do { |x| puts x }for x in 0..8 do puts x end So, we can conclude that both of them are equivalent in terms of performance. If we want to perform operations that modify the local variable passed to the loop, then the times and iterator block expression would come handy. Otherwise, the for loop might come in handy as well. The usage of both of them mutually is a choice of each own programmer.
-
Looping map without scrolling the camera (edge to edge)
wariolandgoldpiramid posted a topic in Programming
I would like certain maps to be looped horizontally, but I don't want to do it with the default MV map features. I want a certain map that is exactly 17 tiles wide to be looped horizontally, but without scrolling the camera. Instead, I want it to be like the looping screens of arcade maps, where having your character go off the edge of the map will make the character automatically come out from the opposite edge, and the camera never scrolls horizontally. -
Okay, I came across yet another problem while making my game and this one is just puzzling to me. Basically, some of the BGM that I have playing in my game does not loop. It just fades out and then it's just dead silence for minutes on end. I have waited a few minutes, not that it just takes a while, but to no avail. Does anyone know why the BGM isn't looping and how I could fix it? I'm not really trying to get it to loop at certain points, I just want it to keep restarting from the beginning, as usual. If it helps, I have a custom song and that song is an .ogv file. Another weird thing is that some of the other custom songs in the game DO loop correctly, even though the songs are the same file type. Is there something I'm missing? Is there a script I need to fix this issue? Any help is appreciated. EDIT: What I did notice is depending on the converter I use, the file output will be either .ogg or .ogv. Is it that the ogv isn't registered to really loop whereas the .ogg is?? That's what my theory is at the moment and I'll probably try a different converter to get the .ogg file but if it doesn't work then I have no clue. EDIT: Okay, I converted the .ogv file to an .ogg file and now it's looping correctly. Welp, I just feel reeaallly stupid now xD At least I figured it out. This thread can be closed now, if it can even count as a thread.
-
Ello folks! I've been playing Fire Emblem: Awakening for a while now, and after I ended up marrying myself to Nowi (best choice in my opinion), I invested myself with some Second Seals, which allow class changes. Now, some might go: "Oh, new class? Ok..." However, these seals allow your stats to be maxed quite well, and if you know what you're doing, you can set your skills up to be a powerhouse among foes. But here I ask... Should there be other games made like this? I mean, sure, you have broken items, like the Temmie Armour from Undertale, Sol from Golden Sun Dark Dawn, just to name a couple, but when you max your stats? There's almost no way you can really be bent into a loss, right? Well, I believe it should be there, in the form as how Pokemon did it, being the IV and EV points, but then you come to other games like Kingdom Hearts, where you could permanently max stats as well. So, before I continue rambling, here's the main jist of my question: Is this a good style for RPG games? If so, why? If not, what do you think is better? (Just a heads up, the setup of the question and all seems a bit broke, and I blame the fruit punch...)
-
stuck trying to figure out how to set up this event
PrkchpsNaplsaws posted a topic in Editor Support and Discussion
EDIT: Nevermind - I figured it out - use "label" and "jump to label" sorry to clog up the forum, please delete this if necessary Basically I want my event to give the "illusion" of choice, but corner you into choosing a particular answer. Like this: Villager: Hello, adventurer! Could I borrow some sugar? Choice: Yes = (check inventory for sugar) if sugar is present = show text "Yaa! Thank you!". If sugar is not present, show text "Hey, wait a second...you don't have any sugar! Come back and see me when you have more sugar!" Set switch to wait for player to have sugar. Choice: No = Hello, adventurer! Could I borrow some sugar? Present choice Yes or No...but I would like it to refer to the first "choice" listed above, instead of re-creating the "same" choice, multiple times (if that is possible?) As long as you keep choosing "No" - the villager will keep asking you to borrow some sugar. I've been plugging away at this for about an hour now, and I think I'm more confused than when I started :\ Any help would be most appreciated


