RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
what does this mess (< 0 ? n : n) mean?

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 82
We learn by living...
Quote
      hit = 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”"
« Last Edit: November 24, 2010, 11:14:21 PM by shintashi »

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Basically, "a = x < 0 ? y : z" is shortform for:

Code: [Select]
if x < 0
  a = y
else
  a = z
end

***
Rep:
Level 90
Skilled Scripter, Shitty Mapper, Decent Writer.
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:
Code: [Select]
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.

***
Rep:
Level 82
We learn by living...
Basically, "a = x < 0 ? y : z" is shortform for:

Code: [Select]
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:
Code: [Select]
      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
Code: [Select]
      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

Code: [Select]
hit = self.cant_evade? ? 20 : hit
      hit_result = (rand(20) < hit)

have me lost.

***
Rep:
Level 90
Skilled Scripter, Shitty Mapper, Decent Writer.
Hard to say really since I don't know if you're using any scripts that alter the way skills work.

***
Rep:
Level 82
We learn by living...
got it working just fine for my friend's game. I even managed to do the opposite and create my own mess:

Code: [Select]
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

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

***
Rep:
Level 82
We learn by living...
it isn't bitwise

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.
« Last Edit: November 26, 2010, 05:04:41 PM by shintashi »

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
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.

Basically, "a = x < 0 ? y : z" is shortform for:
Code: [Select]
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:
Code: [Select]
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*

*
RMRK's dad
Rep:
Level 86
You know, I think its all gonna be okay.
For going the distance for a balanced breakfast.Project of the Month winner for June 2009For being a noted contributor to the RMRK Wiki2013 Best WriterSilver Writing ReviewerSecret Santa 2013 Participant
Oh... ow... my brain just exploded...

Damn, you all smart.
:tinysmile: