Thread: Using static boolean?

Results 1 to 8 of 8
  1. #1 Using static boolean? 
    Apple Computers
    Bridget7298's Avatar
    Join Date
    Aug 2007
    Age
    32
    Posts
    1,088
    Thanks given
    99
    Thanks received
    49
    Rep Power
    219
    In my client.java I have a method for protect of melee:

    Code:
    public static boolean praymelee = false;

    In my NPCHandler I have this:
    Code:
    if(npc == 1615 && client.praymelee == true) {
    addSlayerItem(4);
    }
    But it affects all players? I just don't understand, would I have to change it to:
    Code:
    private static boolean
    I don't know how to do this without affecting every player? I just can't remember how to do it. If anyone could help me out I would be greatly appreciated.
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Sep 2008
    Posts
    4,833
    Thanks given
    894
    Thanks received
    1,439
    Rep Power
    2924
    making the variable static means it won't thread off per instance/client, remove the static and you're good.
    "Know thy self, know thy enemy. A thousand battles, a thousand victories." - Sun Tzu
    GitHub: https://github.com/Faris-Mckay
    Reply With Quote  
     

  3. #3  
    Donator


    Join Date
    Jul 2010
    Posts
    748
    Thanks given
    100
    Thanks received
    67
    Rep Power
    116
    Code:
    if(npc == 1615 && client.praymelee == true && client.playerName.equalsIgnoreCase("name") ) {
    addSlayerItem(4);
    } else {
    return;
    }
    idk try dat. If that's wut you mean...
    Reply With Quote  
     

  4. #4  
    Apple Computers
    Bridget7298's Avatar
    Join Date
    Aug 2007
    Age
    32
    Posts
    1,088
    Thanks given
    99
    Thanks received
    49
    Rep Power
    219
    Quote Originally Posted by Faris View Post
    making the variable static means it won't thread off per instance/client, remove the static and you're good.
    But my protect melee method is in client.java, if I don't declare it static I can't use the praymelee == true in the NPCHandler.java
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jun 2012
    Posts
    175
    Thanks given
    32
    Thanks received
    47
    Rep Power
    35
    Quote Originally Posted by Violent Danz View Post
    But my protect melee method is in client.java, if I don't declare it static I can't use the praymelee == true in the NPCHandler.java
    What are you trying to accomplish? Is the if statement in some kind of attack NPC method? I'll assume it is.

    Lets assume its:

    Code:
    public void attackNpc(int npc) {
    if(npc == 1615 && client.praymelee == true) {
    addSlayerItem(4);
    }
    }
    Add a Client parameter to the method, and whenever you call that method pass in the Client object that's calling it.

    Then you have access to that client and you can see if the boolean is true or not.
    Reply With Quote  
     

  6. #6  
    Apple Computers
    Bridget7298's Avatar
    Join Date
    Aug 2007
    Age
    32
    Posts
    1,088
    Thanks given
    99
    Thanks received
    49
    Rep Power
    219
    so what your saying is like using this code:
    Code:
    client c = server.npc[NPCHandler].npc;
    if(npc == 4 && c.praymelee == true) {
    }
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Jun 2012
    Posts
    175
    Thanks given
    32
    Thanks received
    47
    Rep Power
    35
    Quote Originally Posted by Violent Danz View Post
    so what your saying is like using this code:
    Code:
    client c = server.npc[NPCHandler].npc;
    if(npc == 4 && c.praymelee == true) {
    }
    No. Not trying to be rude, but why does it say "Server Programmer" in your user title if you can't even understand what a parameter is...

    Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    Once you read that, hopefully you'll understand.
    Reply With Quote  
     

  8. Thankful user:


  9. #8  
    Apple Computers
    Bridget7298's Avatar
    Join Date
    Aug 2007
    Age
    32
    Posts
    1,088
    Thanks given
    99
    Thanks received
    49
    Rep Power
    219
    Quote Originally Posted by Bauer24 View Post
    No. Not trying to be rude, but why does it say "Server Programmer" in your user title if you can't even understand what a parameter is...

    Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    Once you read that, hopefully you'll understand.
    Last time I actually worked on a server in detail was like 2 years ago, I just needed a memory refresher.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 59
    Last Post: 08-10-2011, 09:31 PM
  2. Replies: 5
    Last Post: 09-18-2010, 12:08 AM
  3. using static vs not static methods?
    By digistr in forum Application Development
    Replies: 8
    Last Post: 04-30-2010, 11:31 PM
  4. boolean ??
    By devildreams54 in forum Help
    Replies: 4
    Last Post: 08-08-2009, 10:41 AM
  5. Replies: 7
    Last Post: 07-07-2009, 11:12 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •