Please Somebody help me with my code

Discussion in 'Plugin Development' started by DeathOfTime8, Sep 10, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    DeathOfTime8

    Code : http://paste.ubuntu.com/23159808/

    Guys everything works perfectly until line 104 than it's not working it's just always says upgrade failed

    Random method :
    public int random(){
    return random.nextInt(100);
    }

    can some1 help me please
     
    Last edited: Sep 10, 2016
  2. Offline

    DeathOfTime8

    yes i want to make so when some1 upgrade their items there is a change that the item will burn out
     
  3. Offline

    Zombie_Striker

    @DeathOfTime8
    1. Create a random instance
    2. Create an int which is equal to a random number. This represents the chance an item will burn
    3. If the int is equal to 0, burn it.
     
  4. Offline

    JanTuck

    public int random(){
    return new Random().nextInt(100);
    }

    Should be correct
     
  5. Offline

    Zombie_Striker

    @JanTuck
    1. Don't create multiple instances of random. Use ThreadLocalRandom.current.
    2. There is no reason for this to be a method. It is just one line.
    3. There is no reason for this to be public. This will most likely only be used in one class.
    4. Don't spoonfeed. If he needs someone to give him copy-and-paste-able code in order to know how to use the Random object, he should not be here.
     
  6. Offline

    JanTuck

    Okay, sry.

    Iam new to this forum just need to get everything right and understand all the rules and forms.
     
  7. Offline

    DeathOfTime8

    i have problems with the if-else statments can you guys help me with that i dont know what it's not working properly
     
  8. Offline

    Zombie_Striker

    @DeathOfTime8
    What is your problem? Have you debugged? If so, what lines are not working?
     
  9. Offline

    DeathOfTime8

    All if statements after 87 is not working upgrade always fails i made the chance %10 and it still failed 10 times in a row
     
  10. Offline

    Zombie_Striker

    @DeathOfTime8
    Please fix your formatting. It is extremely hard to see the scope of each if statement.

    First, that is how chances should work. Just because you set it to 1%0, that should not mean that the upgrade should happen 1/10 times. You can try 100 times, and if it is really chance, you may never get a single upgrade.

    To really fix this issue: Debug. Find out exactly which line is not working/ not working as intended. Are you returning too soon? Is there an encapsulation problem? Is an if statement never being satisfied?
     
  11. Offline

    DeathOfTime8

    thanks i also want to ask one more thing how can i make the inventory custom for everyone cause currently only 1 people can use it
     
  12. Offline

    Zombie_Striker

    @DeathOfTime8
    Whenever a new player wants to access the inventory, create a new instance of the inventory.
     
Thread Status:
Not open for further replies.

Share This Page