Can i use conditional operator (?) like this?

0 favourites
  • 3 posts
  • 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:

    player.dexterity + 10 + int(player.perk="triforce" ? int((player.dexterity + 10))/5 : 0)[/code:2sbotb0t]
    
    [img="https://s13.postimg.org/46y6242mf/event.jpg"]
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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 ) ?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)