Leaderboard
Popular Content
Showing content with the highest reputation on 05/29/2017 in all areas
-
1 pointI've been posting a bit about baking recently so here's some pics of the goodies. These are the first attempt.The welshcakes came out a little burned obv T.T but everything tasted pretty good. These are the second batch of shortbread. Had a little dough left over hence the Pacman shaped one. These were the cookes that became brownies. To make them the soft chewy kind I used brown sugar and self-raising flour, but yeah, came out too big. And these are the last things I baked. A second batch of welsh cakes that came out looking a lot better than the first.
-
1 pointAlright, so... I know there are many scripts about weapon powers out there, but I wrote something for use within my project. Please feel free to use it the way you'd like to. Features: A new parameter: Weapon Power (WP). Define each weapon and armor's 'weapon power' by note-tagging in the database. Rewrite performance considerations by factoring the weapon power into the equation, meaning that when we select 'optimize', weapon power will also be considered. Here's the code. As always, insert it below the materials section above Main. Place it on top of scripts that will depend on 'wp'. Some damage formulas created by using weapon power (though creativity -is- limitless): The comments box below are open for further discussions. Ideas, suggestions, critiques and feedback are always welcome! <3
-
1 pointAlright, let this post remind me at times I forget this thing. I've been developing an RPG project lately. At present I wanted to modify the equip screen. I've added a new equip slot (ammunition) using Yanfly's Ace Equip Engine. By the time the user selects a projectile weapon, I want them to select an ammunition from their inventory list. The ammunition list shown will correspond to the equipped weapon (you won't get a list of handgun bullets if you're equipping a bowgun). The following method is to remind me to check weapon IDs whether they're a projectile weapon or not. =beginThe projectile weapon IDs are 5, 29, 6, 8, 30, 7, 9, 10, 11, 24.We create a method to check the weapon ID and return true if the weapon is a projectile weapon.=endclass Window_EquipItem < Window_ItemList def projectile?(weapon) return false unless weapon.is_a?(RPG::Weapon) result = false [5, 29, 6, 8, 30, 7, 9, 10, 11, 24].each do |x| result = true if (weapon.wtype_id == x) end return result endend At present, the capabilities are: Able to equip projectile weapons that uses ammunition. The ammunition is defined as armors in the database, but will later be ammunition in-game using Yanfly's Ace Equip Engine's note-tagging. There's a corresponding item at the database. An example works best.Suppose we're equipping a bowgun. The ammunition equipped is a set of birch bolts. There is a 'birch bolt' item in the database entry. Each time the bowgun is fired, one 'birch bolt' will be lost. The attack will fail if we're running out of ammunition, and a corresponding message will be shown. [*]Each weapon has a new 'weapon power' parameter written in the note box by note-tagging (I wrote the code for implementing weapon power). The damage formula will use the weapon power in conjunction with the actor's statistics. I'll post something when this project is starting to make sense.
-
1 point
-
1 pointAs far as I know, yield has to match the passed block's bindings, but other then that there is no limit to how to use it. For example: def something1(a, local_a = a local_b = b # do something to local_a and local_b yield(local_a, local_ end something1(5,6) {|x,y| puts a+b} # needs 2 bound vars def something2(a, local_a = a local_b = b # do something else the largest between local_a and local_b yield([local_a, local_b].max) end something2(3,4) {|x| puts x} # needs only 1 bound var. Also, another way to do it: # same thing as something1 only passes the block into a var def something3(a, b, &block) local_a = a local_b = b # do something to local_a and local_b block.call(local_a, local_ end
-
1 pointThanks, and sorry for replying quite late. :'3 Hmm... Say, if we define a calculation method as above but we want to do processing before the yield operator, can we do it? Something like: def predict(a, local_a = a local_b = b # do something to local_a and local_b yield(local_a, local_ end Also is it possible to yield only one parameter? I mean the procedure requires two parameters but is it possible to yield only one? I'll keep the ! operator in mind, and despite I still quite don't get the sort method, I'll do some experiments. Hmmm... I guess I get it. Ruby isn't as strict about blocks as Python is, and it's convenient, too. I hadn't had the chance to try experimenting with the multi-line stacked if modifier but I'll do try. Thanks :3
-
1 pointThe 'yield' keyword only works with blocks (or fibers kinda). Basically it runs a method's block. Here is an example I found: def calculation(a, yield(a, end puts calculation(5, 6) { |a, b| a + b } # addition puts calculation(5, 6) { |a, b| a - b } # subtraction The '.sort' method mostly works with the special '<=>' operator/method, which basically returns if something is less, equal, or greater. To be exact, I think x <=> y returns -1 if x is less then y, 0 if they are equal, and 1 if x is more then y. Here is another example I found somewhere: a = [ "d", "a", "e", "c", "b" ] a.sort #Default x <=> y gives ["a", "b", "c", "d", "e"] a.sort { |x,y| y <=> x } #Reverse gives ["e", "d", "c", "b", "a"] b = [ [1,2,3], [4], [5,6] ] b.sort { |x,y| x.size <=> y.size } #Sort by sise, gives [ [4], [5,6], [1,2,3] ] Also! And this is important! When you see a method ending in '!' it means it sorts something in place rather then give a new copy. So '.sort' gives you a new copy of an array that is sorted but '.sort!' sorts the array it's self. a = [ "d", "a", "e", "c", "b" ] b = a.sort #now b is set to ["a", "b", "c", "d", "e"] but a is unchanged a.sort! #now a is set to ["a", "b", "c", "d", "e"] Also as for if, as for as I am aware if/else uses blocks. I am pretty sure you can't write it any other way, but I wouldn't be surprised if internally it translates to something closer to a method call like lisp's if statements, aka 'if({condition block}, {true block}, {false block})' or something. And as we have seen, we can write multi-line blocks to split a statement like with 'do'. So I am pretty sure 'then' and 'else' in a single line if acts to delimit the block as if it were using '{}' and a return acts kinda like 'do' would? As long as there is an 'end' it just counts as a block and can treat it right so it doesn't have to be on one line. Not sure the technical way of saying it, but yeah I think that's basically what is happening? Side note: For fun, talking about ruby, blocks, if, and lisp reminded me of something delightful I found once. Because ruby coding with all this built in stuff like if statements and numbers is too mainstream. :3
-
1 pointI should also try experimenting more with the yield keyword. Say, do you know how the sort {|a,b| ...} method works? It's supposed to sort the contents of a collection of objects using a, b and evaluating them in iterator blocks, but I still can't get how it works. Aaaaand, oh, goodness! Thanks for telling me! I usually do the following to avoid nil: x = y unless y.nil? If I haven't erred in understanding, the ||= operator basically assigns the value of y to x unless y is nil, no? Thanks for telling me, this -does- come in handy! Also, since everything returns a value, and ruby interprets, in its logical evaluation, that everything is true unless it's nil or false, it -is- handy. At first I thought this was confusing, yet after understanding how it works, it sure comes in handy oftentimes. And... oh is it acceptable to break if modifiers into multilines? I was afraid it would err the code so I usually do it in one line: x = if y then z else n end # or even x = y ? z : e Thanks for telling me. Breaking the if modifier into multiple lines makes the code easier to read (and I can perform multiple checks and statements inside the if modifier block). The trinary operator...I haven't made use much of them, though, but I'll do learn some of it.


