Quotehit = self.damage < 0 ? 100 : 100 - eva
hit = self.cant_evade? ? 100 : hit
hit_result = (rand(100) < hit)
I'm trying to figure it out and I'm just getting more lost. I think
the last line means
"Hit result is true if d100 is less than 'hit""
Basically, "a = x < 0 ? y : z" is shortform for:
if x < 0
a = y
else
a = z
end
I want to elaborate a little on what cozzie said.
From the looks of that code, I'd say it's the combat code that determines your hit chance. It calculates the original hit chance based on if you caused damage, checks to see if the target can't avoid attacks at all, and then runs a d100 against the hit chance to see if the target gets hit.
In long format code, it'd look like this:
if self.damage < 0 #true/false IF check
hit = 100
else
hit = 100 - eva
end
if self.cant_evade?
hit = 100
end
hit_result = (rand(100) < hit) #random generated number followed by true/false IF check on it
That's a lot of code to parse and run through a translator(RGSS is not a compiled language like C++). I would suspect using a format like cozzie's example, "a = x < 0 ? y : z", would be easier for a computer to parse and translate as opposed to my "long code" example above.
Quote from: cozziekuns on November 25, 2010, 12:00:49 AM
Basically, "a = x < 0 ? y : z" is shortform for:
if x < 0
a = y
else
a = z
end
if you wanted to stick an attack skill in there, where a lower attack skill = better chance to hit, where would you place it?
in:
eva = 0 + self.eva
if self.damage < 0
hit = 20
else
hit = 20 - eva
end
hit = self.cant_evade? ? 20 : hit
hit_result = (rand(20) < hit)
my guess is
eva = 0 + self.eva
if self.damage < 0
hit = 20
else
hit = 20 - attack_skill - eva
end
hit = self.cant_evade? ? 20 : hit
hit_result = (rand(20) < hit)
I would do it normally but these lines
hit = self.cant_evade? ? 20 : hit
hit_result = (rand(20) < hit)have me lost.
Hard to say really since I don't know if you're using any scripts that alter the way skills work.
got it working just fine for my friend's game. I even managed to do the opposite and create my own mess:
backlash = backlash < 0 ? 0 : backlash
for my own game. If I'm not mistaken, this line says "if backlash is less than 0, return 0, else return backlash". I normally call this stuff 'bitwise' even though it probably isn't. :o
it isn't bitwise (http://en.wikipedia.org/wiki/Bitwise_operation)
Quote from: NAMKCOR on November 26, 2010, 07:40:49 AM
it isn't bitwise (http://en.wikipedia.org/wiki/Bitwise_operation)
correct. If it read something like b | a << ~b & b it might be bitwise.
so you guys call this "shortform"? It's pretty cool actually, and works where if ..end statements tend to crash, though I'm not sure why.
Conditional Operator (http://en.wikipedia.org/wiki/Conditional_operator) I think...
It's called the
ternary operator. (A ternary operator is simply an operator which takes three arguments)
A ternary operator is an expression of the
condition ? true_expression : false_expression where either the
true_expression or the
false_expression will be evaluated and the resulting value of that expression will be the resulting value of the ternary operation.
Quote from: cozziekuns on November 25, 2010, 12:00:49 AM
Basically, "a = x < 0 ? y : z" is shortform for:
if x < 0
a = y
else
a = z
end
a is being set to the result of the expression so it's rather a shortform for:
a = if x < 0
y
else
z
end
I can understand why you post it the other way since that is easier to understand ^^
*hugs*
Oh... ow... my brain just exploded...
Damn, you all smart.