Can i use conditional operator (?) like this?

Get help using Construct 2

Post » 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)



Image
B
14
S
3
G
1
Posts: 95
Reputation: 1,015

Post » Sun Mar 19, 2017 10:29 pm

You have a ) in the wrong place.

Right now it reads
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.
Image ImageImage
B
169
S
50
G
174
Posts: 8,330
Reputation: 110,804

Post » 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
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: Blendi1223, jatin1726, Kyatric and 24 guests