Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:39:59+00:00 2026-06-01T19:39:59+00:00

Still new to Java/android so trying to figure out the best way to code

  • 0

Still new to Java/android so trying to figure out the best way to code a multilevel if statement. What I’m trying to do is for a combat system that needs to check if player/npc is alive. If they are alive it then will check to see if they scored a critical hit. If they didn’t critical hit then will see if they hit or missed.

combat = mydbhelper.getCombat();
startManagingCursor(combat);
if (playerCurHp == 0) {
    combat.moveToPosition(11);
    npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
} else {
    if (playerCritFlag.equals("Critical")) {
        combat.moveToPosition(2);
        playerCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
    } else {
        if (playerHitFlag.equals("Hit")) {
            combat.moveToPosition(1);
            playerCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
        }
        if (playerHitFlag.equals("Miss")) {
            combat.moveToPosition(3);
            playerCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
        }
    }
}           
if (npcCurHp == 0) {
    combat.moveToPosition(10);
    npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
} else {
    if (npcCritFlag.equals("Critical")) {
        combat.moveToPosition(5);
        npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
    } else {
        if (npcHitFlag.equals("Hit")) {
            combat.moveToPosition(4);
            npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
        }
        if(npcHitFlag.equals("Miss")) {
            combat.moveToPosition(6);
            npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
        }
    }
}   

Is what I’m using. Was working when I had the if statements all separate. But it would check each one and do actions I don’t need (If they hit, pull String, if crit pull another, then if dead pull again). Trying to make it stop when it finds the “Flag” that matches. When doing my rolls if the player hits it sets the flag to “Hit” like below code.

Random attackRandom = new Random();
int attackRoll = attackRandom.nextInt(100);
totalAtt = attackRoll + bonusAttack + weaponAtt + stanceAtt;
Random defensiveRandom = new Random();
int defenseRoll = defensiveRandom.nextInt(100);
npcDef = defenseRoll + npcDodge + npcBonusDodge;
if (totalAtt > npcDef) {
    playerHitFlag = "Hit";
    playerDamage();
} else {
    playerHitFlag = "Miss";
    npcAttack();
}

At the end it takes these playerCombatStory and npcCombatStory strings and uses them to setText to show the player what happened on that turn of combat.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:40:01+00:00Added an answer on June 1, 2026 at 7:40 pm

    I think you are looking for the else if statement:

    if (condition) {
    
    }
    else if (other_condition) {
    
    }
    else if (another_condition) {
    
    }
    else {
       // There can only be one else statement in a given if-else block
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still new to programming/Java/Android so I'm trying to understand everything I do and
I'm still relatively new to Java and Android development, so I'm still unfamiliar with
I'm still new to code igniter and I'm having problems getting the login system
Can't figure this one out. Done research, searched here, online, etc. Still a new
I'm trying to convert a Java Program to Android. I created a new xml
I'm still quite new to Android and Java programming and even newer to draw
First, i'm new at Java-programming and my native lang is not english, but still
I'm new to android. I have some java knowledge (not extensive), and I've done
I'm relatively new to Java, eclipse and android so this could be a completely
I'm having an issue trying to build a JSONArray in android that has more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.