# Can i use conditional operator (?) like this?

Get help using Construct 2

### » Sun Mar 19, 2017 10:01 pm

Hello!
I'm currently developing roguelike rpg game for android and i'm very satisfied with the results, but i have one question for you about conditional operator (?). In my battle engine, i'm calculating enemy hit chance based on players dexterity: game will generate random integer number between 0 and 51 and if it's less than players dexterity + 10 it will be count as hit. Ok, this works perfect, but now i have added perks to the game that is modifying some gameplay elements. Right now, perk called "Triforce" is adding +20% chance for dodge, so i'm wondering if i can implement it like this:
Code: Select all
`player.dexterity + 10 + int(player.perk="triforce" ? int((player.dexterity + 10))/5 : 0)`

B
15
S
3
G
1
Posts: 96
Reputation: 1,042

### » Sun Mar 19, 2017 10:29 pm

You have a ) in the wrong place.

If player.perk=triforce, then set the value to player.dexterity + 10 + int(int((player.dexterity + 10))/5), else player.dexterity + 10 + int(0)

I think it should be player.dexterity + 10 + int(player.perk="triforce") ? int((player.dexterity + 10))/5 : 0
Last edited by newt on Sun Mar 19, 2017 11:11 pm, edited 1 time in total.
B
175
S
50
G
200
Posts: 8,626
Reputation: 124,528

### » Sun Mar 19, 2017 11:07 pm

Sure, you can use a conditional operator like

player.perk="triforce" ? int((player.dexterity + 10))/5 : 0

but it should be round( (player.dexterity + 10) /5 ) ?
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450