I'm trying to make a damage formula for my abs, and I'm looking at the default RMXP formula.
atk = [attacker.atk - self.pdef / 2, 0].max
self.damage = atk * (20 + attacker.str) / 20
I have no idea what the output of the first line would even look like? Why is it in [] brackets. and what is .max lol
variable = [a, b, c, d, ....].max # gets the biggest value
variable = [a, b, c, d, ....].min # gets the smallest value
example :
atk = [attacker.atk - self.pdef / 2, 0].max
means :
# define atk variable
atk = attacker.atk - self.pdef / 2
# change variable into 0 if atk is negative (below 0)
atk = 0 if atk < 0
it's worth pointing out that "max" and "min" are methods of the enumerable (http://ruby-doc.org/core-1.8.6/Enumerable.html) module which is included in the array class. They will work with far more than just 2 values
max and min assumes that the objects in the enumerable implement Comparable (http://www.ruby-doc.org/core-1.8.6/Comparable.html)
you can also pass max/min a block that works just like sort
array.max { |a, b| a.length <=> b.length }
the <=> (spaceship) operator is special comparison in that instead of returning true or false if one object is bigger than another it returns 1, 0, or -1 if the first object is bigger, equal to, or smaller than the second respectively. you do not need to use the <=> in the block you pass its just a convince. The block simply needs to return 1 if a>b, 0 if a==b, or -1 if a<b.
I didn't even see this post ryex o.o thanks for the info. Never hurts to learn multiple methods of accomplishing something :D